- CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(hello_world)
# CMake Debug/RELEASE版本
SET(CMAKE_BUILD_TYPE "Debug") ## 默认是Release模式,设置为Debug才能调试
#设置Debug版本编译的环境变量:为系统环境变量
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
#设置Debug版本编译时的环境变量:为系统的环境变量
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
#切换环境变量为工程目录CMAKE文件设置的环境变量
#这种方法与上述两种方法只需要一种就可以了
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -g -ggdb")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) # 设置可执行文件的输出目录,感觉很重要喔
add_executable(hello_world main.cc)
2.task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build", //在任务列表中看到的值,取自己喜欢的名字
"type": "shell", //运行task的平台,一般是shell
"args": [],
//相当于 g++ -g main.cpp -std=c++11 -o main.out ,其中main.out可以添加,也可以不添加
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build", //设置为build组,这样当你在vscode中执行build命令时,
//就能自动执行"command"中的命令了
"isDefault": true
}
}
]
}
3.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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/main", //只改这里
"args": [],
"stopAtEntry": true, //打断点
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //如果不要窗口弹出,在ide中显示,就设置成 false
"MIMode": "gdb",
"preLaunchTask": "build", //表示预先生成一个中间文件,用于g++运行
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}