CMake用/ MT编译,而不是/ MD
我在windows上使用cmake与Windows SDK和NMake Makefiles
I'm using cmake on windows with the Windows SDK and NMake Makefiles
默认情况下,它编译/ MD编译器开关。
By default it compiles with the /MD compiler switch.
我如何改变它用/ MT开关编译?
How can I change it to compile with the /MT switch instead?
您可以修改 CMAKE_CXX_FLAGS_< Build Type>
和/或 CMAKE_C_FLAGS_< Build Type>
变量:
You can modify the CMAKE_CXX_FLAGS_<Build Type>
and/or CMAKE_C_FLAGS_<Build Type>
variables:
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
如果您的CMake标志已经包含 MD
,您可以确保在 / MD
插入之后之后执行上述命令添加 / MT
覆盖冲突的现有选项),或者您可以从头设置标记:
If your CMake flags already contain /MD
, you can ensure that the above commands are executed after the point at which /MD
is inserted (the later addition of /MT
overrides the conflicting existing option), or you can set the flags from scratch:
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
b $ b
或者,您可以用 / MD 和 / MDd
$ c> / MT 和 / MTd
分别执行以下操作:
Or alternatively, you could replace the existing /MD
and /MDd
values with /MT
and /MTd
respectively by doing something like:
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()