cmake的debug调试task.json与launch.json

  1. 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
                }
            ]
        }
    ]
}
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值