CMAKE是否支持Windows上的延迟加载DLL?

发布于 2025-02-11 04:05:13 字数 271 浏览 2 评论 0 原文

我正在将MSBuild项目转换为CMAKE项目(IDE是Visual Studio 2022)。

MSBUILD属性页面允许设置所选的DLL被“延迟加载”,但是在线搜索搜索使我找不到有关类似标志或配置设置的信息,无法在我的cmakelists.txt中启用此cmake build时,当我设置target_link_libraries()。

我是否缺少使用CMAKE_变量或其他命令来执行此操作的方法,还是这根本不是Cmake的支持功能,因为它已进化为Linux工具,并且延迟加载并不是真正的事情?

I'm converting a MSBuild project to a cmake project (IDE is Visual Studio 2022).

MSBuild properties page allows setting selected dlls to be "delay-loaded" but searching online leaves me finding nothing about a similar flag or configuration setting to enable this in my CMakeLists.txt for the cmake build when I setup my target_link_libraries().

Am I missing a way to do this with a CMAKE_ variable or other command, or is this simply not a supported feature of cmake since it evolved as a Linux tool and delay-loading isn't really a thing there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桜花祭 2025-02-18 04:05:14

在Cmake 3.24中,这将是可能的,这是我编写此答案时的第二个版本候选人。

foreach (lang IN ITEMS C CXX)
  if (CMAKE_${lang}_COMPILER_ID STREQUAL "MSVC")
    set(CMAKE_${lang}_LINK_LIBRARY_USING_delayload "/DELAYLOAD:<LIBRARY>")
  else ()
    set(CMAKE_${lang}_LINK_LIBRARY_USING_delayload_SUPPORTED FALSE)
  endif ()
endforeach ()

target_link_libraries(lib2 PRIVATE "
lt;LINK_LIBRARY:delayload,lib1>")

我不确定这些围绕这些的最佳实践是什么。在某些情况下,可能需要将上述代码段包括在其导出文件中。可能不是可执行文件的问题,但很可能是库。

This will be possible in CMake 3.24, which is on its second release candidate as I write this answer.

foreach (lang IN ITEMS C CXX)
  if (CMAKE_${lang}_COMPILER_ID STREQUAL "MSVC")
    set(CMAKE_${lang}_LINK_LIBRARY_USING_delayload "/DELAYLOAD:<LIBRARY>")
  else ()
    set(CMAKE_${lang}_LINK_LIBRARY_USING_delayload_SUPPORTED FALSE)
  endif ()
endforeach ()

target_link_libraries(lib2 PRIVATE "
lt;LINK_LIBRARY:delayload,lib1>")

I'm not sure what the best practices surrounding these will be. One might need to include the above code snippet in their export files under some circumstances. Probably not an issue for executables, but might well be for libraries.

https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文