MSVC与CMake和Ninja生成器的增量链接 [英] MSVC Incremental linking with CMake and the Ninja generator

查看:783
本文介绍了MSVC与CMake和Ninja生成器的增量链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上使用CMake和Ninja生成器构建了一个共享库。我想使用增量链接来减少链接所需的时间。

I build a shared library with CMake and the Ninja generator on Windows. I'd like to use incremental linking to reduce the time required for linking.

我尝试将 CMAKE_SHARED_LINKER_FLAGS 设置为 / incremental ,但此标志始终被CMake附加的 / INCREMENTAL:NO 覆盖。

I tried to set CMAKE_SHARED_LINKER_FLAGS to "/incremental" but this flag is always overridden by a "/INCREMENTAL:NO" which is appended by CMake.

我还尝试将 MSVC_INCREMENTAL_DEFAULT 设置为 ON ,但这没有任何作用。

I also tried to set MSVC_INCREMENTAL_DEFAULT to ON, but this didn't have any effect.

那么我如何使用CMake和Ninja生成器进行增量链接?

So how can I get incremental linking working with CMake and the Ninja generator?

推荐答案

将我的评论变成答案

我使用了类似的在我的VS工具链文件中设置(CMAKE_EXE_LINKER_FLAGS_RELEASE / INCREMENTAL:YES缓存字符串强制)

请注意,CMake确实可以合并/附加其链接器标志,例如 CMAKE_SHARED_LINKER_FLAGS 和特定于构建类型的部分,例如 CMAKE_SHARED_LINKER_FLAGS_RELEASE

Be aware that CMake does combine/append its linker flags out of the general e.g. CMAKE_SHARED_LINKER_FLAGS and the build type specific parts like CMAKE_SHARED_LINKER_FLAGS_RELEASE.

因此,您必须找出CMake确实为共享库设置了 / INCREMENTAL:NO 的位置-正如您和我所做的那样-并​​用以下内容覆盖:

So you have to either find out where CMake does set /INCREMENTAL:NO for shared libraries - as you and I have done - and overwrite it with:

set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/INCREMENTAL:YES")

或者您可以遍历不同的构建配置特定变量,例如:

Or you could iterate over the different build configuration specific variables like:


  • CMake使用/ MT而不是/ MD进行编译

  • < a href = http://cmake.3232098.n2.nabble.com/How-to-set-a-preprocessor-define-for-all-build-configurations-except-one-td6450520.html rel = nofollow noreferrer> CMake:如何为除一个以外的所有构建配置设置一个预处理器定义?

  • CMake compile with /MT instead of /MD
  • CMake: How to set a preprocessor define for all build configurations except one ?

这篇关于MSVC与CMake和Ninja生成器的增量链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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