Can I build libc++ to be independent from MSVC? - visual-c++

I know that libc++ support for Windows is experimental but it still can be built, right? I installed latest MSVC Build Tools, installed official clang binaries and successfully built the library.
When I ask clang to use libc++ headers it still keeps searching for urct headers or some internal MSVC headers:
....... C:/Program Files (x86)/libcxx/include/c++/v1\\errno.h
........ C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\errno.h
or
.... C:/Program Files (x86)/libcxx/include/c++/v1\\new
..... C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\new.h
...... C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\include\\vcruntime_new_debug.h
....... C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\include\\vcruntime_new.h
...... C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.24.28314\\include\\crtdefs.h
It compiles successfully but fails to link with undefined references to almost everything (tries to link libc++.lib). But if I don't specify headers it uses MSVC headers and builds successfully with -defaultlib=libcmt. Can I build it to work independently of MSVC or at least what am I doing wrong with using libc++ headers?

Related

How to force cmake to use Visual Studio 2015 (v140) platform toolset?

I installed both VS2015 and VS2017. For a cmake project, I want to use cmake to generate a vs2015 project (platform toolset v140).
I Opened the Developer Command Prompt for VS2015 then I ran cmake there.
But from the output and also the result sln file, I see it's still using vs2017 (v141) platform toolset.
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.16.27027.1
-- The CXX compiler identification is MSVC 19.16.27027.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
Please see the screenshot here:
cmake vs2015
So, how to I force cmake to use vs2015?
This is what the -T option is for:
-T Specify toolset name if supported by generator.
Some CMake generators support a toolset name to be given to the native
build system to choose a compiler. See the CMAKE_GENERATOR_TOOLSET
variable. This is supported only on specific generators:
Visual Studio Generators for VS 2010 and above The Xcode generator for
Xcode 3.0 and above See native build system documentation for allowed
toolset names.
cmake -G "Visual Studio 15 2017" -T v140
(Note that the generator names for Visual Studio changed between CMake 3.13 and 3.14)
This will generate a Visual Studio 2017 solution, using the 2015 compiler and toolchain. So opening the solution will open VS 2017, but the code will compile with the 2015 toolchain.
If you want to use the 2015 IDE instead, you use the 2015 generator and leave out the -T parameter.
Note that you can also install the v140 toolchain as part of a VS2017 installation, so if you don't plan on using the older IDE, there is really no reason for keeping the VS2015 installation around.
cmake -G "Visual Studio 14 2015"
make sure Windows SDK version 10.0.10586.0 is istalled.
to see a list of the generators, run cmake --help

What is the missing of "version.lib" in process of building clang with clang-cl?

I successfully built standalone llvm on windows with clang-cl (clang 8.0 downloadable binary) against back-end msvc build tool 2017 with windows 10 sdk using cmake/ninja
After that when I was building standalone clang, it reported "version.lib" in linking phase of clang-rename.exe is missing.
LINK Pass 1: command "....
" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'version.lib'
The weird thing is that word version.lib was slabbed in place amoung various lib\clang?????.libs and the leading -LIBPATH:llvm\\.\lib
I tried looking for version.lib in both build folders of llvm and clang, and found none.
Am I supposed to have verson.lib in llvm\lib?
What am I missing here?

nvcc.exe linking error Microsoft Visual Studio configuration file 'vcvars64.bat' could not found

I want to use nvcc -ptx from windows command line, but I always get this error message:
nvcc : fatal error : Microsoft Visual Studio configuration file 'vcvars64.bat' could not be found for installation at 'C:\Program Files (x86)\Microsoft Visual S
tudio 11.0\VC\bin/../..'
I'm using vs 2012 express edition. What can be the solution?
I have managed to solve the issue and make work with MS Visual Studio Express 2012, here what I did:
Installed MS Visual Studio 2012 Express
Installed cuda_5.5.20_winvista_win7_win8_general_64, the latest version as of 2014-01-16
From this directory: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin, I have copied x86_amd64 to amd64
In the new directory: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64, I have created a file vcvars64.bat
In the file vcvars64.bat, just added: CALL setenv /x64
The compilation worked great:
C:\CUDA>nvcc -o square square.cu
Creating library square.lib and object square.exp
C:\CUDA>square.exe
0.000000 1.000000 4.000000 9.000000
16.000000 25.000000 36.000000 49.000000
64.000000 81.000000 100.000000 121.000000
144.000000 169.000000 196.000000 225.000000
From NVIDIA CUDA Compiler Driver document
1.2. Supported Host Compilers
nvcc uses the following compilers for host code compilation:
On Linux platforms
The GNU compiler, gcc, and arm-linux-gnueabihf-g++ for cross compilation to the ARMv7
architecture
On Windows platforms
The Microsoft Visual Studio compiler, cl On both platforms, the compiler found on the current
execution search path will be used, unless nvcc option -compiler-bindir is specified (see File and Path Specifications).
Your visual studio install is asking for .NET v3.5 framework:
http://www.microsoft.com/en-us/download/details.aspx?id=21
Got this info from this: Where can I find Microsoft.Build.Utilities.v3.5
When in your project go to Configuration Properties > CUDA C/C++ > Device and change Code Generation to the following: compute_11,sm_11

C1905/LNK1257 Combining x64 Release Libraries

I have set up static library builds of zlib and libpng. Both compile fine into .lib files. I am using MSVC 2010.
With this setup, to use libpng.lib, you need to link against zlib.lib as well. To avoid this, I'm trying to use lib.exe to link zlib into libpng directly. My invocation looks like:
call "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/lib.exe" /OUT:x64\Release\libpng2.lib x64\Release\libpng.lib ..\zlib\x64\Release\zlib.lib /LTCG
In both of their project settings, I explicitly set "Librarian->General->Target Machine" to MachineX64. And, using dumpbin, I can check that the relevant zlib.lib and libpng are both compiled for x64.
Additionally, "General->Whole Program Optimization" and "C/C++->Optimization->Whole Program Optimization" have identical values.
The problem only occurs for x64 Release configurations. x86 Debug, x86 Release, and x64 Debug all work fine.
EDIT: Specifically, the problem is that I get a C1905/LNK1257 error:
C1905: Front end and back end not compatible (must target same processor).
LNK1257: code generation failed
I ran into this problem with VS2012. The lib.exe you're calling is part of the x86 tools. In the amd64 subfolder in VC/bin you will find the x64 versions. Opening a Visual Studio x64 Win64 Command Prompt will set your PATH correctly or you can call the x64 lib.exe directly, specifying its full path as you are doing now.

Cmake is Unable to Configure Project for Visual Studios 10 amd64

I am trying to get CMAKE to create a project for msvc 10 express edition for x64 architecture. I have both MSVC 2010 Express and Windows SDK 7.1 installed.
If I start CMake Normally I can create a 32 bit project, however it fails to make a 64 bit project. I have also Tried starting CMAKE from within the Windows SDK Command Prompt (cl cmd maps to x64 version) however It still fails with the following.
Found Windows SDK v7.1: C:\Program Files\Microsoft SDKs\Windows\v7.1\
Check for working C compiler using: Visual Studio 10 Win64
Check for working C compiler using: Visual Studio 10 Win64 -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "c:/Program Files (x86)/Microsoft Visual Studio
10.0/VC/bin/amd64/cl.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Dan/Desktop/pclt/PCL/bin/CMakeFiles/CMakeTmp
Run Build Command:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
cmTryCompileExec1400574213.vcxproj /p:Configuration=Debug
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.296]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 1/14/2013 8:15:59 AM.
Project
"C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\cmTryCompileExec1400574213.vcxproj"
on node 1 (default targets).
PrepareForBuild:
Creating directory "cmTryCompileExec1400574213.dir\Debug\".
Creating directory "C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\Debug\".
InitializeBuildStatus:
Creating "cmTryCompileExec1400574213.dir\Debug\cmTryCompileExec1400574213.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\CL.exe /c /Zi /W3 /WX- /Od /Ob0 /D WIN32 /D _WINDOWS /D _DEBUG /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"cmTryCompileExec1400574213.dir\Debug\\" /Fd"C:/Users/Dan/Desktop/pclt/PCL/bin/CMakeFiles/CMakeTmp/Debug/cmTryCompileExec1400574213.pdb" /Gd /TC /errorReport:queue C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\testCCompiler.c /Zm1000 /GZ
C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(146,5):
error : Required file "" is missing.
[C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\cmTryCompileExec1400574213.vcxproj]
Done Building Project
"C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\cmTryCompileExec1400574213.vcxproj"
(default targets) -- FAILED.
Build FAILED.
"C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\cmTryCompileExec1400574213.vcxproj"
(default target) (1) ->
(ClCompile target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(146,5): error : Required file "" is missing. [C:\Users\Dan\Desktop\pclt\PCL\bin\CMakeFiles\CMakeTmp\cmTryCompileExec1400574213.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.12
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
Configuring incomplete, errors occurred!
I found that my x64 compilers were destroyed by installing SP 1. Try this update to restore them :
http://www.microsoft.com/en-us/download/details.aspx?id=4422
I had similar issues on Win7, and was getting the same error - The C compiler "cl.exe" is not able to compile a simple test program.
The solution that worked for me :
On Windows Donot run cmake on the cygwin terminal.
Run it from the command prompt, AND also ensure that you have admin rights,
In windows 7 you can start command prompt as administrator by going to
Start->All programs->Accessories-> (Right Click on Command Prompt) and Select "Run as administrator"
Then run cmake <your source>
Worked like a charm for me.

Resources