hello world编译不能通过

在安装了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里面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值