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

后端 未结 2 1841
终归单人心
终归单人心 2020-12-09 10:39

I currently have cmake, clang and ninja installed on windows. I am trying to use CMake to generate a ninja build file to compile a very simple hello world program.

M

相关标签:
2条回答
  • 2020-12-09 11:23

    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 .
    0 讨论(0)
  • 2020-12-09 11:24

    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.

    0 讨论(0)
提交回复
热议问题