下面给你一个从零开始学 Linux 下 C++ 的实用入门路线,侧重“能动手、能跑起来”。
如果没有实体机,可以用:
sudo apt update
sudo apt install g++ gcc make gdb
验证:
g++ --version
mkdir cpp_learn
cd cpp_learn
nano hello.cpp
#include <iostream>
int main() {
std::cout << "Hello Linux C++" << std::endl;
return 0;
}
g++ hello.cpp -o hello
./hello
源码(.cpp) → 预处理 → 编译 → 汇编 → 链接 → 可执行
常见命令:
g++ -E hello.cpp # 预处理
g++ -S hello.cpp # 汇编
g++ -c hello.cpp # 只编译不链接
hello: hello.cpp
g++ hello.cpp -o hello
使用:
make
./hello
iostreamvectorstringmapopen/read/write)fork)pthread)socket)g++ -g hello.cpp -o hello
gdb ./hello
常用命令:
run
break main
next
print x
quit
✅ 多写
✅ 多编译
✅ 多看报错
❌ 不要一上来就学框架
如果你愿意,我可以:
你现在是完全零基础,还是已经会一点 C / C++?