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 to
std::cout’
hello.cpp:(.text+0x1a): undefined reference tostd::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 to
std::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 tostd::ostream::operator<<(std::ostream& (*)(std::ostream&))' /tmp/ccYzLkya.o: In function
__static_initialization_and_destruction_0(int, int)’:
hello.cpp:(.text+0x55): undefined reference tostd::ios_base::Init::Init()' hello.cpp:(.text+0x64): undefined reference to
std::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++的区别,不过暂时懒得查,以后有机会再说吧