Building c++ project on Windows with CMake, Clang and Ninja
Don't know if it can be helpful but I had the same error. Now I can compile with clang(3.7.1)/ninja(1.6)/cmake(3.4.1) on Windows performing the following actions in a build directory:
- load the relevant vcvarsXX.bat file (e.g.
"<Your Visual Studio location>\VC\vcvarsall.bat" x86
) - set both CC and CXX to
clang-cl
(instead ofclang
andclang++
) - run
cmake -G Ninja <project>
- run
cmake --build .
Turns out the second set of errors I received were because clang could not find the linker. I had built clang using visual studio but at the time it couldn't find the visual studio linker. All I had to do was run it in the visual studio development console.
CMake still thinks that clang is a visual studio compiler so in the CMakeDetermineCompilerId.cmake
file there is a line that looks like this:
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
and I changed it to look like this
if (COMPILER_ID MATCHES "MSVC") set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")endif()
Hopefully this doesn't break any other CMake functionality.