<i id='i35MD'><tr id='i35MD'><dt id='i35MD'><q id='i35MD'><span id='i35MD'><b id='i35MD'><form id='i35MD'><ins id='i35MD'></ins><ul id='i35MD'></ul><sub id='i35MD'></sub></form><legend id='i35MD'></legend><bdo id='i35MD'><pre id='i35MD'><center id='i35MD'></center></pre></bdo></b><th id='i35MD'></th></span></q></dt></tr></i><div id='i35MD'><tfoot id='i35MD'></tfoot><dl id='i35MD'><fieldset id='i35MD'></fieldset></dl></div>

        <bdo id='i35MD'></bdo><ul id='i35MD'></ul>

      <small id='i35MD'></small><noframes id='i35MD'>

    1. <legend id='i35MD'><style id='i35MD'><dir id='i35MD'><q id='i35MD'></q></dir></style></legend>

      <tfoot id='i35MD'></tfoot>
    2. 什么是等效于 GCC ld 选项的 Microsoft Visual Studio -

      时间:2023-10-06
    3. <tfoot id='X5SWV'></tfoot>
        <bdo id='X5SWV'></bdo><ul id='X5SWV'></ul>

            <small id='X5SWV'></small><noframes id='X5SWV'>

            <legend id='X5SWV'><style id='X5SWV'><dir id='X5SWV'><q id='X5SWV'></q></dir></style></legend>

            <i id='X5SWV'><tr id='X5SWV'><dt id='X5SWV'><q id='X5SWV'><span id='X5SWV'><b id='X5SWV'><form id='X5SWV'><ins id='X5SWV'></ins><ul id='X5SWV'></ul><sub id='X5SWV'></sub></form><legend id='X5SWV'></legend><bdo id='X5SWV'><pre id='X5SWV'><center id='X5SWV'></center></pre></bdo></b><th id='X5SWV'></th></span></q></dt></tr></i><div id='X5SWV'><tfoot id='X5SWV'></tfoot><dl id='X5SWV'><fieldset id='X5SWV'></fieldset></dl></div>
                <tbody id='X5SWV'></tbody>

              1. 本文介绍了什么是等效于 GCC ld 选项的 Microsoft Visual Studio --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.

                在我们使用 gcc 的 Unix 下,我可以将标志 --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' 选项,包括存档中的每个目标文件
                    在链接中,而不是在存档中搜索所需的
                    目标文件.这通常用于将存档文件转换为
                   一个共享库,强制每个对象都包含在
                    结果共享库.此选项可以多次使用.

                    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.

                注意:这个答案现在已经快 7 年了,关于 MSVC++ 工具链中选项可用性的声明已经过时.尽管如此,我仍然建议不要依赖注册商模式并查看替代方案.由于此建议,请随意投反对票,但我想反对票有点不公平,因为在此期间该选项已添加到 Microsoft 链接器中.

                Caution: this answer is now almost 7 years old and the statements regarding the availability of options in the MSVC++ toolchain are outdated. Nevertheless I still recommend not to rely on registrar pattern and look at the alternatives. Please feel free to down vote because of this recommendation but I guess it's a bit unfair to down vote because the option was added to Microsoft linker in the meantime.

                这篇关于什么是等效于 GCC ld 选项的 Microsoft Visual Studio --whole-archive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:_chkstk() 函数的目的是什么? 下一篇:CUDA 链接错误 - Visual Express 2008 - 由于(空)配置文件

                相关文章

                最新文章

                  <bdo id='1O1r7'></bdo><ul id='1O1r7'></ul>
              2. <tfoot id='1O1r7'></tfoot>
                <i id='1O1r7'><tr id='1O1r7'><dt id='1O1r7'><q id='1O1r7'><span id='1O1r7'><b id='1O1r7'><form id='1O1r7'><ins id='1O1r7'></ins><ul id='1O1r7'></ul><sub id='1O1r7'></sub></form><legend id='1O1r7'></legend><bdo id='1O1r7'><pre id='1O1r7'><center id='1O1r7'></center></pre></bdo></b><th id='1O1r7'></th></span></q></dt></tr></i><div id='1O1r7'><tfoot id='1O1r7'></tfoot><dl id='1O1r7'><fieldset id='1O1r7'></fieldset></dl></div>
                <legend id='1O1r7'><style id='1O1r7'><dir id='1O1r7'><q id='1O1r7'></q></dir></style></legend>

                  1. <small id='1O1r7'></small><noframes id='1O1r7'>