c - CMake、clang、Visual studio下如何设置C11为编译标准?

标签 c windows visual-studio cmake clang

有谁知道在使用 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 的原因。

来源:https://nullprogram.com/blog/2016/06/13/

关于c - CMake、clang、Visual studio下如何设置C11为编译标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58342742/

相关文章:

Windows 7 的设备管理器中没有 "see"Arduino Uno R3 板

C#、WPF、Visual Studio 4 : irregular shape color filling

c++ - 奇怪的预处理

visual-studio - 进程与处理器的处理器时间百分比

Windows Callgrind 结果浏览器,替代 KCacheGrind

c++ - 为什么子窗口可能收不到鼠标事件?

c - ANSI C S-Linked List - deleteLast() 无法正常工作

c - struct node**hashTable 和 struct node*hashTable[MAXSIZE] 之间有什么区别?

在 C 中创建 CLI 应用程序

C无限循环与链表