在 Ubuntu 上配置 C++ 开发环境,通常只需要几步即可完成。下面从最基础到更专业的方式给你介绍。
sudo apt update
sudo apt install build-essential
build-essential 包含:
g++(C++ 编译器)gccmakeg++ --version
能看到版本号就说明成功了。
mkdir ~/cpp_test
cd ~/cpp_test
nano hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello Ubuntu C++" << endl;
return 0;
}
g++ hello.cpp -o hello
./hello
sudo apt install cmake
cpp_test/
├── CMakeLists.txt
└── hello.cpp
cmake_minimum_required(VERSION 3.10)
project(hello)
add_executable(hello hello.cpp)
mkdir build
cd build
cmake ..
make
./hello
sudo snap install code --classic
推荐插件:
sudo apt install gdb
使用:
gdb ./hello
sudo apt install libstdc++-11-dev
sudo apt install gcc-12 g++-12
如果你是为了:
可以告诉我你的使用场景,我可以给你更针对性的配置方案。