我发现了一个非常接近的问题here,但是此后C ++扩展名已被更新,为您创建的launch.json
文件却大不相同,我不确定如何设置它。网上也没有很多信息可以做到这一点,所以我希望有人以前这样做过。我当前的项目结构是这样的:
MainProj
./build
CMakeLists.txt
main.cpp
otherClasses.hpp
将运行build
和..cmake
之后出现在make
中的cmake目标称为Main
。
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": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
这是另一个问题中的task.json文件
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cd build && cmake .. && make"
}
]
}