在Visual Studio中配置Clang-CL与CMake时遇混合编译器错误求助
问题:Visual Studio配置Clang-CL工具链构建CMake项目时出现编译器混合错误
之前在MinGW中使用C23特性,但MinGW在Windows上的调试功能完全无法使用,于是尝试在Visual Studio中配置Clang-CL工具链,使用CMakeLists.txt构建时出现如下错误:
Severity Code Description Project File Line Suppression State Details Error CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.27/Modules/Platform/Windows-Clang.cmake:170 (message): The current configuration mixes Clang and MSVC or some other CL compatible compiler tool. This is not supported. Use either clang or MSVC as both C, C++ and/or HIP compilers. C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.27/Modules/Platform/Windows-Clang.cmake 170
项目配置文件
CMakeLists.txt
cmake_minimum_required(VERSION 3.21) include(FetchContent) find_package(OpenGL REQUIRED) #- GLFW --------------------------------------------------------------------- FetchContent_Declare( glfw GIT_REPOSITORY https://github.com/glfw/glfw GIT_TAG 3.3.8 GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) set(GLFW_BUILD_TESTS OFF CACHE BOOL "") set(GLFW_BUILD_DOCS OFF CACHE BOOL "") set(GLFW_INSTALL OFF CACHE BOOL "") set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "") FetchContent_MakeAvailable(glfw) #- GLAD --------------------------------------------------------------------- FetchContent_Declare( glew GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git GIT_TAG origin/master ) FetchContent_GetProperties(glew) if(NOT glew_POPULATED) FetchContent_Populate(glew) add_subdirectory(${glew_SOURCE_DIR} ${glew_BINARY_DIR} EXCLUDE_FROM_ALL) endif() #- STB --------------------------------------------------------------------- FetchContent_Declare( stb GIT_REPOSITORY https://github.com/nothings/stb.git GIT_TAG master GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) FetchContent_GetProperties(stb) if(NOT stb_POPULATED) FetchContent_Populate(stb) message("Fetching stb") add_library(stb_image INTERFACE ${stb_SOURCE_DIR}/stb_image.h) target_include_directories(stb INTERFACE ${stb_SOURCE_DIR}) endif() #- FREETYPE ----------------------------------------------------------------- FetchContent_Declare( freetype GIT_REPOSITORY https://github.com/aseprite/freetype2.git GIT_TAG VER-2-6-3 ) FetchContent_GetProperties(freetype) if(NOT freetype_POPULATED) FetchContent_Populate(freetype) add_subdirectory(${freetype_SOURCE_DIR} ${freetype_BINARY_DIR}) endif() # -------------------- project(2dgfx C) set(CMAKE_C_STANDARD 23) # set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib) endif() include_directories(. ./deps/include ./lib) link_directories(./deps/lib) # link_libraries(freetype.lib glew32s.lib shell32.lib Gdi32.lib user32.lib opengl32.lib glfw3.lib) add_executable(graphics deps/hash.c deps/hashfunc.c deps/vec.c lib/2dgfx.c main.c) target_link_libraries(graphics PRIVATE glfw libglew_static stb_image)
CMakeSettings.json
{ "configurations": [ { "name": "x64-Debug", "generator": "Ninja", "configurationType": "Debug", "inheritEnvironments": [ "clang_cl_x64" ], "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", "cmakeCommandArgs": "", "buildCommandArgs": "", "ctestCommandArgs": "", "intelliSenseMode": "windows-clang-x64" } ] }
已尝试清理目录、更换工具链、删除缓存等多种方法,耗时数小时仍未解决,恳请帮助。
内容的提问来源于stack exchange,提问作者Aqil Contractor
相关产品推荐
相关产品推荐

