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