我试图在Visual Studio上设置Clang-CL。我需要它,因为我以前在MinGW上使用C23功能,但MinGW在Windows上提供的调试功能无法使用,当我需要它们时根本没有帮助。当我选择Clang-CL工具包后尝试使用CMakeLists.txt文件设置它时,我得到了这个错误:x1c 0d1x
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和CMakeSettings.json:
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)
{
"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"
}
]
}
的数据
我试着清理目录,把工具箱换成别的东西,删除该高速缓存,还有其他很多事情,花了好几个小时,都没有用。
1条答案
按热度按时间xwbd5t1u1#
我将
CMAKE_C_COMPILER
作为clang-cl
,将CMAKE_CXX_COMPILER
作为clang++
。将后者更改为clang-cl
解决了这个问题。这很奇怪,因为这意味着Visual Studio附带的工具包默认情况下会损坏。