开发者

Purpose of --enable-auto-import Warning

开发者 https://www.devze.com 2023-04-12 18:31 出处:网络
I am trying to compile the following program: #include <iostream> int main(){ std::cout << \"Hello, world!\";

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 (开发者_如何学Cauto-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


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:\WINDOWS\System32\cmd.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

    Purpose of --enable-auto-import Warning

  • Right part of the command

    Purpose of --enable-auto-import Warning

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

  • Creating aliases on Windows


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消