目录
GCC交叉编译环境的配置
- 安装gcc编译器(C++为g++)
sudo apt-get install gcc
- 检测是否安装成功
gcc --version
VSCODE环境配置
运行
- 下载插件: C/C++ Extension Pack
- 下载插件: Code Runner
这样就可以简单的编译运行一个简单的C文件了
调试
- 点击左边的调试按钮,然后点击调试,这时候它会自动生成.vscod文件,并且有aunch.json和tasks.json文件
- 将下列代码复制到launch.json内并保存
{
"version": "2.0.0",
"tasks": [{
"label": "compile",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- 将下列代码复制到tasks.json中去。
{
"version": "2.0.0",
"tasks": [{
"label": "compile",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
注:如果需要是c语言也就是gcc将下面的command项由g++改为gcc
多文件编译
- 点击CodeRunner设置,扩展设置
- 找到Code-runner: Executor Map选项,点击设置,将设置复制为json文本
- 点击在settings.json中编辑
- 打开settings.json文件,空行处粘贴
- 找到"c" “cpp"选项将”$fileName"分别修改成*.c和*.cpp
参考资料
菜鸟入门之一:在Ubuntu18.04下利用VS code编写C语言的配置
Linux/Ubuntu中Vs Code配置C++/C环境
VsCode配置成编译多文件(C/C++)