工程结构应该是这样的。
└── foocpp
├── .vscode
│ ├── launch.json
│ └── tasks.json
├── README.md
└── src
├── MainEntry.cpp
├── foo.cpp
└── foo.h
1 open the folder foocpp with vscode
2 configure launch.json and tasks.json
//======================================
launch.json
//======================================
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/foobar.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "build foocpp",
}
]
}
//======================================
tasks.json
//======================================
{
"version": "2.0.0",
"tasks": [
{
"label": "build foocpp",
"type": "shell",
"command": "g++",
"args": [
"-g","-std=c++14" ,"${workspaceRoot}/*/*.cpp", "-ofoobar.out"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}