使用CMake使用/ MT而不是/ MD进行编译 [英] Compile with /MT instead of /MD using CMake

查看:558
本文介绍了使用CMake使用/ MT而不是/ MD进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有Windows SDK和NMake Makefile的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")

或者,您也可以替换现有的 / MD 和<$ c $通过执行以下操作分别使用 / MT / MTd 的c> / 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屋!

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