使用 CMake 编译/MT 而不是/MD [英] Compile with /MT instead of /MD using CMake
问题描述
我在带有 Windows SDK 和 NMake Makefiles 的 Windows 上使用 CMake.
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_
和/或 CMAKE_C_FLAGS_
变量:
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")
或者,您可以用 /MT
和 /MTd
替换现有的 /MD
和 /MDd
值> 分别通过执行以下操作:
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()
这篇关于使用 CMake 编译/MT 而不是/MD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!