在 Linux 下学习 C++,可以按照环境准备 → 基础学习 → 动手实践 → 进阶提升的路径来进行。下面给你一套比较系统、适合新手的方案。
最常见的 C++ 编译器是 g++(GNU 编译器)。
Ubuntu / Debian:
sudo apt update
sudo apt install g++ build-essential
CentOS / Rocky / Alma:
sudo yum install gcc-c++
检查是否安装成功:
g++ --version
新手推荐:
VS Code 安装(Ubuntu 示例):
sudo apt install code
mkdir cpp_learn
cd cpp_learn
touch hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello, Linux C++!" << endl;
return 0;
}
g++ hello.cpp -o hello
./hello
中文
英文
hello: hello.cpp
g++ hello.cpp -o hello
使用:
make
./hello
sudo apt install cmake
CMakeLists.txt 示例:
cmake_minimum_required(VERSION 3.10)
project(learn)
add_executable(hello hello.cpp)
编译:
mkdir build
cd build
cmake ..
make
g++ -g hello.cpp -o hello
gdb ./hello
常用命令:
runbreak mainnextprint x适合新手的小项目:
如果你愿意,我可以:
你现在是完全零基础还是已经会一点 C / C++?