如何使 VSCode 中 CMake Debug 的输出显示在 cmd 上而不是自带的 debug console

如何使 VSCode 中 CMake Debug 的输出显示在 cmd 上而不是自带的 debug console

首先需要明确的一点是从 VSCode 插件商店下载的 CMake 是默认打印输出的结果在 debug console 中的,就像下面这样:

在这里插入图片描述

可以看到,一个问题是在加载 dll 时候会频繁的打印在 Debug Console 里面,从而导致我们本来想要输出的内容很难找到,另一方面,我在使用 spdlog 的时候,输出的内容本身是具有颜色的,就像下面这样:

在这里插入图片描述

但是在 Debug Console 中就只能显示成蓝色了,导致强迫症患者巨难受,因此在网上各种找办法,终于找到了解决方法:

那就是放弃 CMake 插件,使用我们从官方下载的 CMake 并且在 VSCode 中添加配置文件之后来进行编译。下面正式开始:

1. 前提条件:

你的电脑已经装有从官方下载的 CMake,VisualStdio ,确保你的电脑上有 msvc 编译环境。

2. 配置 launch.json 文件

如果找不到 launch.json 请 ctrl+Shift+P 然后输入 launch:

在这里插入图片描述

{
    // 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": "msvc",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/Editor.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "console": "integratedTerminal",
            "preLaunchTask": "build",
            "logging": {
                "moduleLoad": false
            }
        }
    ]
}

然后像上面一样进行配置即可,name 名字为 msvc,注意 program 为你自己的可执行行程序目录。

我们本次最需要关注的就是 "console": "integratedTerminal", 这条语句表明了我们的控制台选项,一共有三个:

integratedTerminal::VS Code’s integrated terminal. 也就是内置终端

internalConsole::Output to the VS Code Debug Console. 输出到内置控制台

externalTerminal :Console applications will be launched in an external terminal window. 输出到外部终端

三种效果分别为:

请添加图片描述

请添加图片描述

3. 配置 tasks.json 文件

还需要进行任务配置

{
	"version": "2.0.0",
	"tasks": [
		{
			//使用本地默认编译器编译cmake
			"type": "shell",
			"label": "cmake",
			"command": "cmake -B ./build ."
		},
		{
			//使用本地默认编译器编译cmake生成的工程
			"type": "shell",
			"label": "make",
			"command": "cmake --build ./build"
		},
		{
			//依次执行前面两个步骤
			"label": "build",
			"dependsOrder": "sequence",
			"dependsOn": [
				"cmake",
				"make"
			]
		}
	]
}

然后按下 F5 便可以正常编译了。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值