在 CentOS 上安装 C++ 编译器,通常是通过安装 GCC(GNU Compiler Collection) 来实现的。以下是详细步骤:
sudo yum update
sudo yum install gcc gcc-c++
gcc:C 编译器gcc-c++:C++ 编译器(g++)g++ --version
或
gcc --version
看到版本信息即说明安装成功。
vi hello.cpp
内容如下:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, CentOS C++!" << endl;
return 0;
}
g++ hello.cpp -o hello
./hello
输出:
Hello, CentOS C++!
如果是 CentOS 8 或 CentOS Stream:
sudo dnf install gcc gcc-c++
如果你要做 C/C++ 开发,可以一次性安装常用开发工具:
sudo yum groupinstall "Development Tools"
包含:
需要配置 yum 源或使用离线 RPM 包。
CentOS 7 默认 GCC 是 4.8,可安装 Software Collections (SCL):
sudo yum install centos-release-scl
sudo yum install devtoolset-11
scl enable devtoolset-11 bash
如果你告诉我:
我可以给你更精确的安装方案。