linux 下安装 c++编译器的方法



假设你的电脑能够访问internet,这个命令会自动从网络下载并把软件安装到本地。

超级用户权限:


#yum -y install gcc-c++


另外一定不要天真的认为linux 下面 编译C++程序,可以用直接用gcc filename.cc,否则会莫名的出现好多链接错误错误。如下:

oot@fedora-odl-1 test]# gcc temp.cc
/tmp/ccGyH0kl.o: In function `main':
temp.cc:(.text+0x87): undefined reference to `std::cout'
temp.cc:(.text+0x8c): undefined reference to `std::ostream::operator<<(int)'
temp.cc:(.text+0x91): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
temp.cc:(.text+0x99): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccGyH0kl.o: In function `__static_initialization_and_destruction_0(int, int)':
temp.cc:(.text+0xc7): undefined reference to `std::ios_base::Init::Init()'
temp.cc:(.text+0xd6): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
[root@fedora-odl-1 test]#

用g++编译则没有问题了  呵呵

或者用gcc指定链接库

gcc temp.cc -lstdc++因为gcc默认不会去链接C++库。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HehuaTang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值