Ubuntu18.04 + VSCode + CMake
- VSCode安装不必多说
- VSCode安装完成后,在扩展中搜索安装以下扩展插件
- C/C++
- C/C++ Compile Run
- CMake
- Cmake Tools
- 在项目中新建.vsocde文件夹,在文件夹中加入launch.json、task.json、c_cpp_properties.json三个配置文件
- launch.json 按F5调试的时候会执行这个配置文件,该配置文件的作用是运行编译生成的可执行文件,所以按照流程我们首先要编译生成可执行文件,编译生成可执行文件的操作由task.json完成,所以我们要在launch.json中要指明task.json中的任务名称,让其先执task.json编译生成可执行文件,然后再执行launch.json运行编译生成的可执行文件。
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build",
}
]
}
- task.json 见名知意,执行一些任务的配置文件
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "mkdir build; cd ./build; cmake ../; make",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- c_cpp_properties.json 主要用于在代码编写过程中检索头文件,没有该配置文件不影响编译运行,但是在代码中会提示找不到头文件什么的。
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**",
"/usr/local/opencv4.2/include/opencv4/**",
"/usr/local/darknet/include/**",
"/usr/local/seetaface6/include/**",
"/usr/local/cuda-10.0/include/**"// cuda
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
- 目录结构大致如下
ProjetcName ├── build ├── CMakeLists.txt ├── test.cpp └── .vscode ├── c_cpp_properties.json ├── launch.json └── tasks.json
|