--enable-auto-import 警告的目的

2022-01-11 00:00:00 mingw linker c++

我正在尝试编译以下程序:

I am trying to compile the following program:

#include <iostream>
int main(){
    std::cout << "Hello, world!";
    return 0;
}

当我编译它时,我得到这个消息:

When I compile it, I get this message:

C:programs>g++ test.cpp
Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
 from auto-imported DLLs.

构建成功并且可执行文件按预期运行,但这个警告仍然让我恼火.我希望一个成功的构建完全沉默.此消息给人一种错误的印象,即我的代码有问题.

The build succeeds and the executable runs as expected, but this warning still irritates me. I expect a successful build to be completely silent. This message gives the false impression that there's something wrong with my code.

我可以使用 g++ -Xlinker --enable-auto-import test.cpp 消除此错误,但这是不可取的,因为它会使我需要键入的字符数增加三倍以编译程序.

I can silence this error with g++ -Xlinker --enable-auto-import test.cpp, but this is undesirable, as it triples the number of characters I need to type to compile a program.

问题:

  • 为什么最简单的程序会出现此警告?当我编译 Hello World 时,我不希望出现神秘的警告.
  • 是否可以在不每次都将标志传递给链接器的情况下消除此警告?可能是隐藏在 c:mingw 某处的配置文件中的一个选项?或者我在安装过程中错过了自动启用自动导入"复选框?
  • Why does this warning appear for the simplest of programs? i don't expect cryptic warnings when I compile Hello World.
  • Is it possible to silence this warning without passing the flag to the linker every time? An option in a config file hidden somewhere in c:mingw, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?

可能相关的规格

  • GCC 版本 4.5.0
  • ld.exe 版本 2.20.51.20100613
  • Windows XP Service Pack 3

推荐答案

我做了一些阅读,看起来它可能与未定义 dllimport 属性的 mingw32 dll 有关.

I did some reading and it looks like it might be related to the mingw32 dll not having dllimport attributes defined.

也许有补丁或者你可以自己重建mingw32并添加它们?

Perhaps there is a patch or you can rebuild mingw32 yourself and add them?

相关文章