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:
c:\mingw
, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?Possibly Relevant Specs
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
Right part of the command
For more information on creating aliases on windows, see this:
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With