vscode设置C++调试功能
安装如下插件clang-format、CMake、CMake Tools,设置好C_Cpp: Clang_format_path
vscode 工程 #include <opencv2/opencv.hpp> 下有波浪线
- 使用Cmakelist.txt检索文件
cmake_minimum_required(VERSION 3.10)
project(test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(OpenCV_DIR /home/ly/Public/opencv-4.5.5/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
- 按F5 生成c_cpp_properties.json、launch.json,该文件在.vscode目录下
- c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
launch.json:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/ldmk_blink",
"args": [
"--face=/home/ly/Projects/face-alg-mnn/model/face/version-RFB/RFB-320.mnn",
"--landmark=/home/ly/Projects/face-alg-mnn/model/landmark/slim_160_latest.mnn"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
- 如果还是有问题,关闭重新打开
vscode C++ 语言格式
- 首先 preference --> setting,搜索clang,设置如下

- 安装clang-format
sudo apt install clang-format - 在工程根目录设置.clang-format文件,内容如下:
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
Language: Cpp
# 基于某一主题上的修改
BasedOnStyle: Google
# 缩进宽度
IndentWidth: 4
# 缩进case标签
IndentCaseLabels: false
# 访问说明符(public、private等)的偏移
AccessModifierOffset: -4
# 每行字符的限制,0表示没有限制
ColumnLimit: 0
# 对齐连续的尾随的注释
AlignTrailingComments: true
# 允许函数声明的所有参数在放在下一行
AllowAllParametersOfDeclarationOnNextLine: false
# 允许短的if语句保持在同一行
AllowShortIfStatementsOnASingleLine: false
# 允许短的case标签放在同一行
AllowShortCaseLabelsOnASingleLine: true
# 允许短的循环保持在同一行
AllowShortLoopsOnASingleLine: false
# 允许排序#include
SortIncludes: true
版权声明:本文为ly0303521原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。