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

Anton Yartsev anton.yartsev at gmail.com
Thu Mar 3 19:30:08 EST 2016


Hi all,

I'm trying to use Clang, compiled with VS 2013 (configuration:Release, 
platform:x64) as a C/C++ compiler for a simple HelloWorld CMake project. 
Generation ends up with errors like "clang.exe: error: no such file or 
directory: '/DWIN32'" at compiler check stage. If I understand correctly 
the problem is that MSVC compiler options are fed to Clang for some 
reason (maybe the "-- The C compiler identification is unknown" log 
entry is related to the problem?).
Could anyone help to resolve this, please?

I also tried to change compiler ID with "-DCMAKE_C_COMPILER_ID=Clang 
-DCMAKE_CXX_COMPILER_ID=Clang", then compilation succeeded, but linkage 
failed (just as described in the thread "Question on usage of cmake on 
Windows with clang" 
http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/54650). 
Here the problem seems to be reversed: GNU linker options are fed to MS 
linker.

************** Setup and details:
1) INCLUDE and PATH set to clang/clang-cl
2) command line environment is configured with vsvars32.bat
3) CC and CXX set to clang

$ cat CMakeLists.txt
project(test_project)
add_executable(main file.cpp)

$ cmake -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang ..

Log:
-- The C compiler identification is unknown
-- 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.src/-VS_build VS
   2013-/Release/bin/clang.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-/CMakeFiles/CMakeTmp

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

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

   FAILED: D:\-Work-\LLVM-3~2.SRC\-VS_BU~2\Release\bin\clang.exe /DWIN32
   /D_WINDOWS /W3 -o CMakeFiles\cmTC_2cb9d.dir\testCCompiler.c.obj -c
   testCCompiler.c

   clang.exe: error: no such file or directory: '/DWIN32'
   clang.exe: error: no such file or directory: '/D_WINDOWS'
...

OS: Windows 7 (x64)

clang version 3.7.1 (tags/RELEASE_371/final)
Target: x86_64-pc-windows-msvc
Thread model: posix

cmake version 3.5.0-rc3

Thank you!

-- 
Anton



More information about the CMake mailing list