【发布时间】:2023-05-01 21:25:01
【问题描述】:
所以,我想使用 CMake 和 clang 作为 VS2019 的前端来构建我的项目。我已经尝试过: CMakeLists.txt
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
#(CMAKE_INSTALL_PREFIX "C:\\Program Files\\LLVM\\bin")
project(sink)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++17 -pedantic")
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}/bin")
file(GLOB SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.cc" "${SRC_DIR}/*.c")
file(GLOB HEADERS "${INCLUDE_DIR}/*.h" "${INCLUDE_DIR}/*.hpp")
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
CMakeSettings.json
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH=\"C:\\Program Files\\LLVM\\bin\\clang-cl.exe\"",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"variables": []
}
]
}
我得到了哪些错误:
1> CMake generation started.
1> Command line: E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\theha\projects\sink"
1> Working directory: C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.20.27404.0
1> [CMake] -- The CXX compiler identification is Clang 7.0.1
1> [CMake] -- Check for working C compiler: E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe
1> [CMake] -- Check for working C compiler: E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe -- works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe
1> [CMake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- broken
1> [CMake] CMake Error at E:/VS19/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.13/Modules/CMakeTestCXXCompiler.cmake:45 (message):
1> [CMake] The C++ compiler
1> [CMake]
1> [CMake] "C:/Program Files/LLVM/bin/clang-cl.exe"
1> [CMake]
1> [CMake] is not able to compile a simple test program.
1> [CMake]
1> [CMake] It fails with the following output:
1> [CMake]
1> [CMake] Change Dir: C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeTmp
1> [CMake]
1> [CMake] Run Build Command:"E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "cmTC_9e38f"
1> [CMake] [1/2] Building CXX object CMakeFiles\cmTC_9e38f.dir\testCXXCompiler.cxx.obj
1> [CMake] FAILED: CMakeFiles/cmTC_9e38f.dir/testCXXCompiler.cxx.obj
1> [CMake] C:\PROGRA~1\LLVM\bin\clang-cl.exe /nologo -TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /JMC /showIncludes /FoCMakeFiles\cmTC_9e38f.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_9e38f.dir\ -c testCXXCompiler.cxx
1> [CMake] clang-cl.exe: error: no such file or directory: '/JMC'
1> [CMake] ninja: build stopped: subcommand failed.
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake]
1> [CMake] CMake will not be able to correctly generate this project.
1> [CMake] Call Stack (most recent call first):
1> [CMake] CMakeLists.txt:5 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "C:/Users/theha/CMakeBuilds/7c084052-2033-9235-9a50-93f9ca5000be/build/x64-Debug/build/CMakeFiles/CMakeError.log".
1> [CMake]
1> CMake generation finished.
1> E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\theha\CMakeBuilds\7c084052-2033-9235-9a50-93f9ca5000be\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="E:/VS19/VC/Tools/MSVC/14.20.27404/bin/HostX86/x64/cl.exe" -H. -G Ninja -Bbuild -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="E:\VS19\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\theha\projects\sink" returned with exit code: 1
那么,我该如何解决呢?也许我做错了什么,但我不明白实际上是什么?我还看到了有关使用 vcvarsall.bat 并设置 CXX 和 CXXFLAGS 的建议,但这无济于事。
【问题讨论】:
-
@drescherjm 究竟需要传递哪些选项?
标签: c++ visual-studio cmake clang ninja