有谁知道在使用 Visual Studio 2019、CMake 和 Clang 时如何将 C 标准设置为 C11。
目前,我有这个,但出于某种原因,clang 无法将其识别为标志:
if(WIN32)
add_definitions("-std=c11 -D _CRT_SECURE_NO_WARNINGS")
endif(WIN32)
而是将其编译为 C++
CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.10.2)
PROJECT(cpu LANGUAGES C VERSION 0.0.1 DESCRIPTION "6502 emulator")
set(CMAKE_BINARY_DIR "./")
set(CMAKE_C_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_BUILD_TYPE DEBUG)
find_package(Curses COMPONENTS)
file(COPY "./headers/cpu.h" DESTINATION "${CMAKE_BINARY_DIR}/headers/cpu.h")
include_directories(headers)
file(GLOB CPU_SOURCES "src/cpu.c" "src/logger.c" "src/cartridge.c")
file(GLOB MONITOR_SOURCES "src/ui/[A-Za-z]*.c")
if(WIN32)
add_definitions("-std=c11 -D _CRT_SECURE_NO_WARNINGS")
endif(WIN32)
if(UNIX)
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std:c11 -Wall -Wextra -fsanitize=address -fsanitize=undefined -DDEBUG")
set(CMAKE_C_FLAGS "-std=c11")
target_link_options(cpu PUBLIC "-D DEBUG")
target_link_options(monitor PUBLIC "-D DEBUG ")
endif(UNIX)
add_library(cpu STATIC ${CPU_SOURCES})
add_executable(monitor ${MONITOR_SOURCES})
set_target_properties(cpu PROPERTIES PUBLIC_HEADER "../headers/cpu.h")
target_link_libraries(monitor cpu)
if(Curses_FOUND)
include_directories(${CURSES_INCLUDE_DIR})
target_link_libraries(monitor ${CURSES_LIBRARIES})
else (NOT Curses_FOUND)
target_link_libraries(monitor)
endif(Curses_FOUND)
最佳答案
我刚刚发现 apparantly clang 使用官方 windows SDK 进行编译,所以我很确定这就是我不能使用 c11 的原因。
关于c - CMake、clang、Visual studio下如何设置C11为编译标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58342742/