[CMake] Problem using VS-compiled Clang as a C/C++ compiler.

Anton Yartsev anton.yartsev at gmail.com
Thu Mar 10 17:44:41 EST 2016


> Hi Anton,
>
> My setup is:
>
>   * Visual Studio 2013 x86 and amd64
>   * Clang 3.7.1 64 bit installed in c:\Program Files\LLVM\
>   * CMake 3.5.0
>   * Ninja 1.5.3
>   * C++ Hello World CMake project
>
> Visual Studio 2013 amd64
> ====================
>
> 1. Opened a command prompt and run "C:\Program Files (x86)\Microsoft 
> Visual Studio 12.0\VC\vcvarsall.bat" amd64
> 2. set INCLUDE=c:\Program Files\LLVM\lib\clang\3.7.1\include\;%INCLUDE%
> 3. set PATH=c:\Program Files\LLVM\msbuild-bin\;%PATH%
> 4. cmake -G "Ninja" ..\helloworldcmake
> CMake output was:
>
>     $ cmake -G "Ninja" ..\helloworldcmake
>     -- The C compiler identification is Clang 3.7.1
>     -- The CXX compiler identification is Clang 3.7.1
>     -- Check for working C compiler using: Ninja
>     -- Check for working C compiler using: Ninja -- works
>     -- Detecting C compiler ABI info
>     -- Detecting C compiler ABI info - done
>     -- Check for working CXX compiler using: Ninja
>     -- Check for working CXX compiler using: Ninja -- works
>     -- Detecting CXX compiler ABI info
>     -- Detecting CXX compiler ABI info - done
>     -- Detecting CXX compile features
>     -- Detecting CXX compile features - failed
>     -- Configuring done
>     -- Generating done
>     -- Build files have been written to:
>     C:/Projects/C++/helloworldcmake-build
>
>
Hi Cristian,

Great thanks for your assistance! Now I see, that it is possible to use 
Clang.
I've tried many different combinations of LLVM/ninja versions: ninja 
1.5.3/1.6.0, LLVM x86/x64 prebuild and compiled from the scratch. 
Neither of this succeeded.
I also managed to reproduce the linkage error "LINK : error LNK2001: 
unresolved external symbol mainCRTStartup" when VC++ and Clang mismatch.

The best approach I got with the following setup:
* Windows 7 x64
* Visual Studio 2013 Update 4
* Clang 3.7.1 x64 bit installed in D:\-Work-\LLVM_3.7.1_win64
* CMake 3.5.0
* Ninja 1.5.3

1) "C:\Program Files\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64
2) SET INCLUDE=D:\-Work-\LLVM_3.7.1_win64\lib\clang\3.7.1\include;%INCLUDE%
3) SET PATH=D:\-Work-\LLVM_3.7.1_win64\msbuild-bin;%PATH%
4) cmake -G "Ninja" ..

--------------------------------------------------- CMake output:
-- The C compiler identification is Clang 3.7.1
-- The CXX compiler identification is Clang 3.7.1
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
CMake Error at C:/Program 
Files/CMake/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
   The C compiler "D:/-Work-/LLVM_3.7.1_win64/msbuild-bin/cl.exe" is not 
able
   to compile a simple test program.

   It fails with the following output:

    Change Dir: 
D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/CMakeTmp



   Run Build Command:"C:/PROGRA~1/ninja/ninja.exe" "cmTC_6d431"

   [1/2] Building C object CMakeFiles\cmTC_6d431.dir\testCCompiler.c.obj

   [2/2] Linking C executable cmTC_6d431.exe

   FAILED: cmd.exe /C "cd .  && "C:\Program Files\CMake\bin\cmake.exe" -E
   vs_link_exe --intdir=CMakeFiles\cmTC_6d431.dir --manifests --
   C:\PROGRA~1\MICROS~2.0\VC\bin\link.exe /nologo
   CMakeFiles\cmTC_6d431.dir\testCCompiler.c.obj /out:cmTC_6d431.exe
   /implib:cmTC_6d431.lib /pdb:cmTC_6d431.pdb /version:0.0 /machine:x64 
/debug
   /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib
   winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib
   advapi32.lib && cd ."

   RC Pass 1 failed to run.



   ninja: build stopped: subcommand failed.





   CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
   CMakeLists.txt:1 (project)


-- Configuring incomplete, errors occurred!
See also 
"D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/CMakeOutput.log".
See also 
"D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/CMakeError.log".

--------------------------------------------------- CMakeError.log
Determining if the C compiler works failed with the following output:
Change Dir: D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/CMakeTmp

Run Build Command:"C:/PROGRA~1/ninja/ninja.exe" "cmTC_6d431"
[1/2] Building C object CMakeFiles\cmTC_6d431.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_6d431.exe
FAILED: cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E 
vs_link_exe --intdir=CMakeFiles\cmTC_6d431.dir --manifests  -- 
C:\PROGRA~1\MICROS~2.0\VC\bin\link.exe /nologo 
CMakeFiles\cmTC_6d431.dir\testCCompiler.c.obj  /out:cmTC_6d431.exe 
/implib:cmTC_6d431.lib /pdb:cmTC_6d431.pdb /version:0.0 /machine:x64  
/debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib 
gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
comdlg32.lib advapi32.lib && cd ."
RC Pass 1 failed to run.


ninja: build stopped: subcommand failed.

--------------------------------------------------- CMakeOutput.log
The system is: Windows - 6.1.7601 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" 
succeeded.
Compiler: D:/-Work-/LLVM_3.7.1_win64/msbuild-bin/cl.exe
Build flags:
Id flags:

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" 
produced "CMakeCCompilerId.exe"

The C compiler identification is Clang, found in 
"D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/3.5.0/CompilerIdC/CMakeCCompilerId.exe"

Compiling the CXX compiler identification source file 
"CMakeCXXCompilerId.cpp" succeeded.
Compiler: D:/-Work-/LLVM_3.7.1_win64/msbuild-bin/cl.exe
Build flags:
Id flags:

The output was:
0


Compilation of the CXX compiler identification source 
"CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.exe"

The CXX compiler identification is Clang, found in 
"D:/-Work-/llvm-3.7.1.src/-CLANG-/ProjectDir/CMakeFiles/3.5.0/CompilerIdCXX/CMakeCXXCompilerId.exe"

----------------------------------------------------------------------------

If I understand correctly Clang managed to build the test file. But 
build failed for unknown reason.. Have no idea what is wrong.
Could you, please, show me the contents your CMakeCache.txt left from 
the successful x64 cmake build?


> And as you can see, I didn't set any CC, CCX, CMAKE_C_COMPILER_ID or
> CMAKE_CXX_COMPILER_ID variables.
I had to set CC and CXX when MinGW was in PATH, now I removed MinGW from 
PATH to reduce influencing factors.

-- 
Anton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160311/d0c9b980/attachment.html>


More information about the CMake mailing list