什么是Microsoft Visual Studio等效于GCC ld选项--whole-archive [英] What is the Microsoft Visual Studio equivalent to GCC ld option --whole-archive
问题描述
将静态库与可执行文件链接时,通常会丢弃未引用的符号。在我的情况下,一些未使用的对象被用于注册他们各自的类到工厂,如果对象被丢弃,这个注册失败。
When linking a static library against an executable, unreferenced symbols are normally discarded. In my case some otherwise unused objects are used to register their respective classes into a factory and if the objects are discarded, this registration fails.
在Unix下我们使用gcc,我可以将标志--whole-archive传递给链接器ld(参见下面ld文档的摘录),这使得ld不丢弃任何对象。对Visual C ++有这样的东西吗?
Under Unix where we use gcc, I can pass the flag --whole-archive to the linker ld (see excerpt from ld documentation below), which makes ld not discard any objects. Is there anything like this for Visual C++?
- 整个档案
--whole-archive
对于命令行上在
--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.
推荐答案
据我所知,是没有一个可靠保证的选项。有优化选项的组合(默默地)停用这个,所以没有办法... / INCLUDE
工程,但为了你需要提取和硬编码的符号。您有两个选择:(1)确保所有注册商都包含(包含)在包含 main
的翻译单元中,并强制使用它们。 (2)放弃这个成语并使用明确的注册。
To my knowledge, there is no single option which reliably guarantees that. There are combinations of optimizing options which (silently) deactivate this, so no way... /INCLUDE
works, but for that you need to extract and hardcode the mangled name of the symbol. You have two choices: (1) ensure, that all registrars are contained (included) in the translation unit containing main
and enforce their usage. (2) Give up this 'idiom' and use explicit registration.
这篇关于什么是Microsoft Visual Studio等效于GCC ld选项--whole-archive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!