在安装了MinGW的Windows系统上,利用G++编译CPP源文件,如果直接用G++ name.cpp会报错,
warning: auto-importing has been activated without –enable-auto-import specified on the command line.
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
Info: resolving std::cin by linking to __imp___ZSt3cin (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without –enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbolsfrom auto-imported DLLs.
出现这个错误的原因是自动导入链接库编译器选项没有提供,我们得在编译时,把–enable-auto-import选项加进去。
另外还有一个问题,默认G++编译时,不会把libstdc++库编进去,那么我们编译出来的程序就不能在没有libstdc++链接文件的电脑上运行。
要么我们把libstdc++链接文件跟我们生成的exe文件都打包到安装程序里面,安装的时候拷进去。
要么我们就要把链接文件编译到exe里面去。
下面给出玩整的编译命令:E:\cpp\first>g++ -Wl–enable-auto-import -static-libgcc -o first.exe first.cpp-Wl Pass comma-separated on to the linker (传递逗号分隔的选项给链接器)-static-libgcc 静态编译链接文件到exe里面