【发布时间】:2020-08-13 11:14:02
【问题描述】:
我最近遇到了一个奇怪的问题(上周有效,但我不明白发生了什么变化)
像往常一样,我使用以下命令行运行 cmake,以便在 Windows 上使用 Visual Studio 2019 工具为某些 c 或 c++ 库配置发布版本:
cmake "./Sources" -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_INSTALL_PREFIX="./Build" -DCMAKE_C_FLAGS="-DNDEBUG -MT -Ob2 -O2 -FS"
但是几天后,我尝试的每个发布版本都会收到此错误:
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:1 (PROJECT):
No CMAKE_C_COMPILER could be found.
-- Configuring incomplete, errors occurred!
进一步调查表明,问题来自 cmake 用于检查编译器的工具,不知何故,它似乎不关心 -DCMAKE_BUILD_TYPE=Release 参数,并尝试将其编译为 Debug 版本。我在 CMakeError.log 中找到了这个:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\CL.exe /c /nologo /W0 /WX- /diagnostics:column /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc142.pdb" /Gd /TP /FC /errorReport:queue CMakeCXXCompilerId.cpp
Build FAILED.
"C:\cpplibs\Intermediate\JsonCpp\1.9.3\Windows\x64\Release\CMakeFiles\3.17.20032601-MSVC_2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(ClCompile target) ->
cl : command line warning D9025: overriding '/MDd' with '/MT' [C:\cpplibs\Intermediate\JsonCpp\1.9.3\Windows\x64\Release\CMakeFiles\3.17.20032601-MSVC_2\CompilerIdCXX\CompilerIdCXX.vcxproj]
cl : command line warning D9025: overriding '/Od' with '/O2' [C:\cpplibs\Intermediate\JsonCpp\1.9.3\Windows\x64\Release\CMakeFiles\3.17.20032601-MSVC_2\CompilerIdCXX\CompilerIdCXX.vcxproj]"C:\cpplibs\Intermediate\JsonCpp\1.9.3\Windows\x64\Release\CMakeFiles\3.17.20032601-MSVC_2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(ClCompile target) ->
cl : command line error D8016: '/RTC1' and '/O2' command-line options are incompatible [C:\cpplibs\Intermediate\JsonCpp\1.9.3\Windows\x64\Release\CMakeFiles\3.17.20032601-MSVC_2\CompilerIdCXX\CompilerIdCXX.vcxproj]
我还打开了生成的 CompilerIdCXX.vcxproj,它只包含一个调试配置,而我要求一个发布版本!因此,这解释了为什么会覆盖多个编译器选项,特别是为什么 /RTC1 存在并声明与 /O2 等预期版本选项不兼容...
我也在我的同事计算机上尝试过,对于其他纯“c”语言的库,它生成一个 CompilerIdC.vcxproj 项目,结果是一样的,因为几天前它就像一个魅力一样工作。
有没有人知道如何让 cmake 恢复正常行为以配置发布版本?
【问题讨论】:
-
您说这曾经有效,但现在无效。您使用的是哪个版本的 CMake?
标签: windows cmake visual-studio-2019