b站视频地址
有launch.json和task.json文件后直接在vscode中按f5就可以编译和调试修改后的代码,不需要在命令行中执行cmake 和make才能看到代码修改后的结果。也可以对代码进行断点调试的功能。
cmake_minimum_required(VERSION 3.0)
project(SOLIDERFIRE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_BUILD_TYPE Debug)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
add_executable(my_cmake_exe main.cpp src/Gun.cpp src/Soldier.cpp)
先任意打开一个.cpp文件
vscode左边竖条选项栏,运行和调试–创建launch.json文件–程序编辑区右下角添加配置–选择C++/C(gdb)启动选项。即可出现以下内容,需要添加的部分是
,"preLaunchTask": "Build", //用来调用task.json中label为Build语句下的内容
launch.json文件内容
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/image_file_read", //此处改为你CMakeLists.txt中可执行文件的名称和路径
"args": [],
//main 函数需要输入参数的话 用下面的格式输入参数
// "args": [
// "~/Downloads/rgbd_dataset_freiburg1_room/",
// "../associate.txt"
// ],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "Build", //用来调用task.json中label为Build语句下的内容
}
]
}
vscode顶部-点击终端–点击最后一项配置默认生成任务–点击CMake:test–即可生成默认的task.jason文件
b站视频里保护cmake 和 make功能的tasks.json 文件内容
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": []
},
{
"label": "Build", //该label用来调用前两句label中的命令,
"dependsOrder": "sequence", // 按列出的顺序执行任务依赖项
"dependsOn": [
"cmake",
"make"
]
}
]
}
参考添加头文件
在vscode中按Ctrl+Shift+P 输入configuration 在c_cpp_properties.json中includePath字段中添加待添加的SDK或者库的头文件路径 例:“/usr/local/xxx/include/”
,
"/home/wxh/baidunetdisk/slambook2/3rdparty/Sophus"
同时CMakeLists中也添加头文件路径
include_directories(/home/wxh/baidunetdisk/slambook2/3rdparty/Sophus)
参考
https://blog.csdn.net/m0_38055352/article/details/105375367
ctrl+shift+P 找到c_cpp_properties.json文件 如下图
在安装过C/C++插件的条件下
vscode中找到.vscod文件夹下的
c_cpp_properties.json文件
在"includePath": [后面添加常用头文件路径
"includePath": [
"${workspaceFolder}/**",
"/usr/include/eigen3",
"/usr/include/c++/7",
"/usr/include/x86_64-linux-gnu/c++/7",
"/usr/include/c++/7/backward",
"/usr/lib/gcc/x86_64-linux-gnu/7/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
// "/opt/ros/noetic/include/ros",
"/opt/ros/noetic/include",
"/usr/local/pcl-1.8.0/pcl/include/pcl-1.8",
"/usr/include/vtk-7.1"
],
https://blog.csdn.net/wbvalid/article/details/115001149
此方法暂时没找到ubuntu下的配置方法,暂不使用
全局的配置在setting.json
文件中
ctr+shift+P 搜索 setting
选择这一项就可以打开setting.json
这一项的打开工作区设置(JSON)只会影响到当前工作区
需要
ctr+shift+P 搜索 /User/settings.json
打开用户设置(JSON)
才能影响到全部的工作区,任意打开窗口都会加载这个文件
在 c_cpp_properties.json 文件的"includePath": [
后面添加 全局的配置
"${default}" //只需要加这一行,可以包含用户设置setting.json中的头文件地址内容
用户设置的setting.json文件可以参考
{
"workbench.colorTheme": "Default Dark+",
"[python]": {
"editor.formatOnType": true
},
"[cpp]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"cmake.configureOnOpen": true,
"window.zoomLevel": 1,
"terminal.integrated.enableMultiLinePasteWarning": false,
"git.enabled": false,
// 后面是自己加的
"C_Cpp.default.includePath": [
"/usr/include/opencv4",
"/usr/include/eigen3",
"/usr/include/c++/7",
"/usr/include/x86_64-linux-gnu/c++/7",
"/usr/include/c++/7/backward",
"/usr/lib/gcc/x86_64-linux-gnu/7/include",
"/usr/local/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/local/pcl-1.8.0/pcl/include/pcl-1.8",
"/usr/include/vtk-7.1",
]
}
https://blog.csdn.net/m0_56996859/article/details/123623598
因为这是git仓库要追踪你的修改,以便管理版本库
VScode里面的 文件 →首选项→设置→搜索Git: Enable 关闭即可
TabOut插件可以在输入代码时按tab键跳转输入位置