在Ubuntu中搭建C++开发环境是一个相对简单的过程,以下是详细的步骤指南:
sudo apt update
sudo apt install build-essential
build-essential
包包含了 gcc
、g++
和 make
等必要的编译和调试工具。
Visual Studio Code:一个流行的轻量级代码编辑器,支持多种编程语言。
sudo snap install --classic code
CLion:一个强大的C/C++ IDE,提供深入的代码分析和智能代码辅助。可以从JetBrains官网下载CLion的tar.gz文件,然后解压到合适的目录。
sudo unzip /path/to/CLion.tar.gz -d /opt/clion
sudo apt install gdb
sudo apt install cmake
安装C/C++扩展包。
配置 tasks.json
和 launch.json
文件来设置编译和调试参数。
hello_world.cpp
:#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
g++ hello_world.cpp -o hello_world
./hello_world
这将在当前目录下生成一个名为 hello_world
的可执行文件,你可以运行它以确认环境配置正确。
通过以上步骤,你就可以在Ubuntu上搭建一个基本的C++开发环境。根据你的需求,你还可以安装更多的开发工具和插件来提升开发效率。