Debian 系统 C++ 配置步骤
一 安装编译工具与调试器
二 验证安装与环境检查
三 编译与运行第一个程序
#include <iostream>
int main() { std::cout << "Hello, Debian C++\n"; return 0; }
四 多文件项目与构建工具
CXX := g++
CXXFLAGS := -Wall -Wextra -std=c++17 -g
TARGET := app
SRCS := main.cpp util.cpp
OBJS := $(SRCS:.cpp=.o)
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
rm -f $(OBJS) $(TARGET)
使用:make 编译,make clean 清理。cmake_minimum_required(VERSION 3.10)
project(MyApp LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(myapp main.cpp util.cpp)
mkdir -p build && cd build
cmake ..
make
./myapp
五 多版本 GCC 切换与 VS Code 配置
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 120 --slave /usr/bin/g++ g++ /usr/bin/g++-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 130 --slave /usr/bin/g++ g++ /usr/bin/g++-13