vscode配置c++调试环境
安装vscode插件创建vscode配置文件配置launch.json{// 使用 IntelliSense 了解相关属性。// 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(gdb) 启动",
·
安装vscode插件

创建vscode配置文件

配置launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/server",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"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",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
配置tasks.json
{
"version": "2.0.0",
"options": {
// cd 到build目录
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command":"cmake",
"args": [
".."
]
},
{
"label": "make",
"command":"make",
"group": {
"kind": "build",
"isDefault": true
},
//"command":"mingw32-make",
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence", // 按列出的顺序执行
"dependsOn":[
"cmake",
"make"
]
}
// {
// "type": "cppbuild",
// "label": "build",
// "command": "/usr/bin/g++",
// "args": [
// "-fdiagnostics-color=always",
// "-g",
// "${file}",
// "-o",
// "${fileDirname}/${fileBasenameNoExtension}"
// ],
// "options": {
// "cwd": "${fileDirname}"
// },
// "problemMatcher": [
// "$gcc"
// ],
// "group": {
// "kind": "build",
// "isDefault": true
// },
// "detail": "调试器生成的任务。"
// }
]
}
创建CMakeLists.txt
这里配置g++为编译工具,加载mysql链接的过程放在生成可执行文件 add_executable之后,以及添加了调试信息-g -O2 -Wall
cmake_minimum_required(VERSION 3.0)
project(SERVER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -Wall -lpthread -lmysqlclient")
set(CMAKE_BUILD_TYPE Debug)
include_directories(${CMAKE_SOURCE_DIR}/timer ${CMAKE_SOURCE_DIR}/http ${CMAKE_SOURCE_DIR}/CGImysql )
add_executable(server main.cpp ./timer/lst_timer.cpp ./http/http_conn.cpp ./log/log.cpp ./CGImysql/sql_connection_pool.cpp webserver.cpp config.cpp)
#mysql所需的头文件和库所需的目录和库文件可以用/usr/bin/mysql_config来查看
include_directories("/usr/include/mysql")
link_directories("usr/lib/x86_64-linux-gnu")
set(MYSQL_LIBS
mysqlclient pthread z m rt atomic ssl crypto dl
)
target_link_libraries(server ${MYSQL_LIBS})
F5断点调试
这里会限制性luanch.json里面的"preLaunchTask": “Build”,也就是对应tasks.json里面的的label,齐总tasks执行了cmake …/ 以及 make操作
更多推荐
所有评论(0)