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

Cristian Adam cristian.adam at gmail.com
Thu Mar 10 05:47:47 EST 2016


On Thu, Mar 10, 2016 at 12:48 AM, Anton Yartsev <anton.yartsev at gmail.com>
wrote:

> Oops, sorry, confused with different variants.
>
> I've tried
> $SET CC=D:\LLVM-3.7.1\bin\clang-cl.exe
> $SET CXX=D:\LLVM-3.7.1\bin\clang-cl.exe
> $cmake -G "Ninja" ..
>
> Compilation succeeded, linkage has ended up with "clang-cl.exe: error:
> unable to execute command: program not executable".
> The same result with clang-cl.exe renamed to cl.exe.
>


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


Visual Studio 2013 x86
=================

1. Opened a command prompt and run "C:\Program Files (x86)\Microsoft Visual
Studio 12.0\VC\vcvarsall.bat" x86
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 -- broken
CMake Error at
C:/Tools/cmake-3.5.0/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61
(message):
  The C compiler "C:/Program Files/LLVM/msbuild-bin/cl.exe" is not able to
  compile a simple test program.

  It fails with the following output:

   Change Dir: C:/Projects/C++/helloworldcmake-build/CMakeFiles/CMakeTmp



  Run Build Command:"C:/Tools/ninja/ninja.exe" "cmTC_89c35"

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

  [2/2] Linking C executable cmTC_89c35.exe

  FAILED: cmd.exe /C "cd .  && C:\Tools\cmake-3.5.0\bin\cmake.exe -E
  vs_link_exe --intdir=CMakeFiles\cmTC_89c35.dir --manifests --
  C:\PROGRA~2\MICROS~3.0\VC\bin\link.exe /nologo
  CMakeFiles\cmTC_89c35.dir\testCCompiler.c.obj /out:cmTC_89c35.exe
  /implib:cmTC_89c35.lib /pdb:cmTC_89c35.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 ."

  LINK : error LNK2001: unresolved external symbol mainCRTStartup

  cmTC_89c35.exe : fatal error LNK1120: 1 unresolved externals

  LINK Pass 1 failed.  with 1120

  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 "C:/Projects/C++/helloworldcmake-build/CMakeFiles/CMakeOutput.log".
See also "C:/Projects/C++/helloworldcmake-build/CMakeFiles/CMakeError.log".



Clang people say that both Clang builds (32 or 64 bit) can compile both 32
and 64 bit
applications. [1]

As it turns out this statement is not completely true :)

I've installed the 32 bit Clang 3.7.1 version to c:\Program Files
(x86)\LLVM\ and tried
again:

Visual Studio 2013 x86
=================

1. Opened a command prompt and run "C:\Program Files (x86)\Microsoft Visual
Studio 12.0\VC\vcvarsall.bat" x86
2. set INCLUDE=c:\Program Files
(x86)\LLVM\lib\clang\3.7.1\include\;%INCLUDE%
3. set PATH=c:\Program Files (x86)\LLVM\msbuild-bin\;%PATH%
4. cmake -G "Ninja" ..\helloworldcmake

This time the 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


This means that you have to match your Visual C++ compiler with the Clang
one!

And as you can see, I didn't set any CC, CCX, CMAKE_C_COMPILER_ID or
CMAKE_CXX_COMPILER_ID variables.

Cheers,
Cristian.

[1] https://llvm.org/bugs/show_bug.cgi?id=26212#c5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160310/575ab279/attachment-0001.html>


More information about the CMake mailing list