在Debian系統上,GCC(GNU Compiler Collection)與IDE(集成開發環境)的集成可以通過多種IDE實現,例如Visual Studio Code(VS Code)、Eclipse等。以下是使用VS Code進行集成的詳細步驟:
sudo apt update
sudo apt install software-properties-common apt-transport-https curl
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "deb [archamd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update
sudo apt install code
打開VS Code,在擴展市場中搜索并安裝“C/C++”插件。
配置launch.json和tasks.json文件:
F5或點擊左側調試圖標,然后點擊“創建一個launch.json文件”。launch.json文件,例如:{
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json文件來配置編譯任務:{
"version": "2.0.0",
"tasks": [
{
"label": "g++ build active file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
運行或調試:
F5開始調試,或點擊調試工具欄中的綠色三角形運行程序。launch.json中的miDebuggerPath指向正確的調試器路徑。libc6-dev和libstdc++6-dev等開發包:sudo apt-get install libc6-dev libstdc++6-dev
通過以上步驟,你可以在Debian系統上使用Visual Studio Code與GCC集成進行C/C++開發。如果使用的是其他IDE,如Eclipse,可以參考相應的官方文檔進行配置。