Reputation: 23
my os version is sierra 10.12.1 and vs code version is 1.8.1. I installed c++ plugin in vs code. And then I created a c++ project. There was my c++ source file.
my_simple.cc
int main(int argc, char const *argv[])
{
printf("%s\n", "******begin******");
int a = 1;
int b = a;
printf("%s\n", "******end******");
return 0;
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "pre_compile",
"showDisplayString": true,
"name": "my_debug",
"type": "cppdbg",
"request": "launch",
"program": "${file}.o",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"osx": {
"MIMode": "lldb"
}
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": [
],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "pre_compile",
"args": [
"${file}",
"-o${file}.o"
],
"isBuildCommand": true
}
]
}
When I add some breakpoints to my_simple.cc and then press f5 to compile and run it. The breakpoints did not work as expected. Please help me find the mistake in my code. Thanks
Upvotes: 2
Views: 996
Reputation: 74
1) create new CMakeList.txt with:
cmake_minimum_required(VERSION 3.0)
project(FirstProgram)
set(SOURCE Hello.cpp)
add_executable(${PROJECT_NAME} ${SOURCE})
2) Task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "sh",
"isShellCommand": true,
"args": ["-c"],
"showOutput": "always",
"suppressTaskName": true,
"options": {
"cwd": "${workspaceRoot}/build"
},
"tasks": [
{
"taskName": "cmake",
"args": ["cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug .."]
},
{
"taskName": "make",
"args": ["make -j 8"],
"isBuildCommand": true
}
]
}
3) launch.json:
{
"version": "0.2.0",
"configurations": [
{
"showDisplayString": true,
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/Build/FirstProgram",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
4) Task Run --> cmake and then: make
Upvotes: 1