我正在使用 CMake 生成我的库的构建系统。我有一些示例程序,而我将语言标准设置为 C++11:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
现在,对于 Windows 构建,我(或者更确切地说是 GitHub)在 Windows 10 上使用 MSVC 16。对于这个程序:
add_executable(bandwidthtest modified_cuda_samples/bandwidthtest/bandwidthtest.cpp)
我得到这个由 CMake 生成的编译命令(我认为它是 CMake 3.26.3;为了便于阅读,换行):
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\CL.exe
/c /I"D:\a\cuda-api-wrappers\cuda-api-wrappers\src"
/I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include" /nologo /W4
/WX- /diagnostics:column /O2 /Ob2 /D _MBCS /D WIN32 /D _WINDOWS /D NDEBUG
/D _CRT_SECURE_NO_DEPRECATE /D _CRT_SECURE_NO_WARNINGS
/D _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING /D "CMAKE_INTDIR=\"Release\""
/Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"bandwidthtest.dir\Release\\" /Fd"bandwidthtest.dir\Release\vc142.pdb" /external:W0
/Gd /TP /errorReport:queue
/external:I "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/include" /Zc:__cplusplus
"D:\a\cuda-api-wrappers\cuda-api-wrappers\examples\modified_cuda_samples\bandwidthtest\bandwidthtest.cpp"
所以,这没有
/std
选项。它确实有 /Zc:__cplusplus
,但我自己添加了那个(我认为 CMake 也应该添加它,但这是一个 known open issue)。
为什么CMake不添加
/std:c++11
?
Microsoft Visual Studio 2019 不支持 C++11: /std (Specify Language Standard Version) 缺失
/std:c++11
.