c++ - 什么是 Microsoft Visual Studio 等效于 GCC ld 选项 --whole-archive

标签 c++ visual-c++ linker static-libraries

将静态库链接到可执行文件时,通常会丢弃未引用的符号。在我的情况下,一些其他未使用的对象用于将它们各自的类注册到工厂中,如果这些对象被丢弃,则此注册失败。

在我们使用 gcc 的 Unix 下,我可以将标志 --whole-archive 传递给链接器 ld(参见下面 ld 文档的摘录),这使得 ld 不会丢弃任何对象。 Visual C++ 有这样的东西吗?

--whole-archive

    For each archive mentioned on the command line after the
    `--whole-archive' option, include every object file in the archive
    in the link, rather than searching the archive for the required
    object files. This is normally used to turn an archive file into
    a shared library, forcing every object to be included in the
    resulting shared library. This option may be used more than once.

最佳答案

Visual Studio 2015 Update 2 中的 Visual C++ 版本在 link.exe 中包含一个名为 /WHOLEARCHIVE 的新标志,它具有与 等效的功能- -whole-archive 选项到 ld。根据the flag documentation :

The /WHOLEARCHIVE option forces the linker to include every object file from either a specified static library, or if no library is specified, from all static libraries specified to the LINK command.

关于c++ - 什么是 Microsoft Visual Studio 等效于 GCC ld 选项 --whole-archive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3867254/

相关文章:

c++ - 了解函数是否在运行时获取引用或值

c++ - clang:使用 O3 导出隐式实例化函数的符号

c++ - forward_list 迭代器稳定吗?

c++ - 为什么 C++ 变量声明语法不一致?

c++ - 字符串比较在 Visual C++ 2005 中不起作用

c++ - 什么是内存更昂贵。 "creating and deleting objects"还是 "reusing a object"?

c++ - 对 ctor 和 dctor 简单代码的 undefined reference

tomcat下的java.lang.UnsatisfiedLinkError

C++ 子字符串似乎指向错误的位置

visual-c++ - 为什么在 WIN8 下使用 Touch Injection API 时只能注入(inject)一次触摸?