Building c++ project on Windows with CMake, Clang and Ninja

妖精的绣舞 提交于 2019-11-28 23:26:22

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:

  1. load the relevant vcvarsXX.bat file (e.g. "<Your Visual Studio location>\VC\vcvarsall.bat" x86)
  2. set both CC and CXX to clang-cl (instead of clang and clang++)
  3. run cmake -G Ninja <project>
  4. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!