centos上的C++

centos8.0
这次弄了个centos服务器,想在服务器上跑c++,命令


总结

yum install gcc-c++
g++ hello.cpp
./a.out

如果出问题可以试试:

yum -y update gcc

调错过程

g++ hello.cpp

1报错:

bash: g++: command not found

1解决:

yum -y update gcc

不行:
换个命令

gcc hello.cpp

2换种报错

gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory

2解决

yum install gcc-c++

3报错

/tmp/ccYzLkya.o: In function main': hello.cpp:(.text+0x15): undefined reference tostd::cout’
hello.cpp:(.text+0x1a): undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' hello.cpp:(.text+0x1f): undefined reference tostd::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)’
hello.cpp:(.text+0x27): undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))' /tmp/ccYzLkya.o: In function__static_initialization_and_destruction_0(int, int)’:
hello.cpp:(.text+0x55): undefined reference to std::ios_base::Init::Init()' hello.cpp:(.text+0x64): undefined reference tostd::ios_base::Init::~Init()’
collect2: error: ld returned 1 exit status

3解决:换回命令

g++ hello.cpp

3输出

[root@iZ0jlgvo0oni8s4kigdjgdZ chatroom]# g++ hello.cpp
[root@iZ0jlgvo0oni8s4kigdjgdZ chatroom]# ./a
bash: ./a: No such file or directory
[root@iZ0jlgvo0oni8s4kigdjgdZ chatroom]# ./a.out
hello, world
[root@iZ0jlgvo0oni8s4kigdjgdZ chatroom]#

呵呵。。


最后
我是真的不太明白gcc和g++的区别,不过暂时懒得查,以后有机会再说吧

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值