Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c++ - Purpose of --enable-auto-import Warning

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.

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.

Questions:

  • 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?

Possibly Relevant Specs

  • GCC Version 4.5.0
  • ld.exe Version 2.20.51.20100613
  • Windows XP Service Pack 3
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I used to face same problem as you do with g++. I solved this irritating problem just now. Here is how I come to the solution, step-by-step:

On Windows, you can create an alias of g++ with all given options which you want to use with g++. Say, for example, you want to create an alias s++ of g++ -enable-auto-import, then you run this on cmd as:

C:>doskey s++=g++ -enable-auto-import

This creates an alias called s++. But this alias will not take any command line argument, which means, you cannot write this:

C:>s++ filename.cpp //it is not working

To make it work, if you've to tell the alias to accept command line arguments while creating it, so here is how it is done:

C:>doskey s++=g++ -enable-auto-import $*

Please note the $* at the right, which indicates that now s++ can take command line argument:

C:>s++ filename.cpp //yayyyy..its working now, without giving any warnings!

But you may not prefer to create the alias everytime you open cmd. In that case, you can create a shortcut of cmd.

For example, I created a shortcut called Console and in the Target textbox of shortcut window, I wrote this:

C:WINDOWSSystem32cmd.exe /K doskey s++=g++ -enable-auto-import $*

And since this is too long (horizontally), one screenshot was not able to capture the entire command. I took two screenshots so that you could see yourself how I did it:

  • Left part of the command

    Left part of the command

  • Right part of the command

    Right part of the command

For more information on creating aliases on windows, see this:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...