CMake用/ MT编译,而不是/ MD [英] CMake compile with /MT instead of /MD

查看:1514
本文介绍了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

或者,您可以用<$ c替换现有的 / 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()

这篇关于CMake用/ MT编译,而不是/ MD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆