已解决:could not find the task ‘g++ build active file,leetcode算法ACM编译调试

项目场景:

环境:ubuntu20.04

工具:VSCode

由于leetcode不能调试代码(要冲会员),所以本地配置环境来运行代码。

leetcode的代码是帮你配置好了所有的环境,你只需要编写核心的代码即可,但是在面试的时候需要你自己编写所有的代码。是ACM模式的(自己百度ACM),这个时候如果你没有经常编写全部代码,很容易蒙圈(我在线上面试深信服的时候就是这样的情况)

在这里插入图片描述

所以自己配置本地环境,编写算法实现的全部过程是很有必要的,包括cpp文件的编译过程和原理,debug过程也可以使得自己更加熟悉代码运行的流程。

编译环境的配置参考:https://code.visualstudio.com/docs/cpp/config-linux

不要百度,不要百度!看官方说明永远是最好的!!!看不懂英文可以直接右键翻译网页。

我的task.json配置:自动生成的,电脑和环境配置不同,这个文件可能会有些不一样。

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++ 生成活动文件",
			"command": "/usr/bin/g++",
			"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "编译器: /usr/bin/g++"
		}
	]
}

我的launch.json:

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "g++ build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "g++ build active file",
        "miDebuggerPath": "/usr/bin/gdb"
      }
    ]
  }

问题描述:

在配置编译C++的task.json、调试配置文件launch.json时遇到下面这种情况。
在这里插入图片描述


原因分析:

代码遇到问题建议直接google,不要百度,也不要问我为什么…

参考:https://stackoverflow.com/questions/59106732/visual-studio-code-debugger-error-could-not-find-the-task-gcc-build-active-f

In your task.json file, no task is labeled as ‘gcc build active file’ which is required as a preLaunchTask in launch.json file.

So you can either change the label of task or change the content of preLaunchTask to make them match.

回答的很清楚:task.json文件这个配置

"label": "C/C++: g++ 生成活动文件",

和launch.json的这个配置必须要是一样的

"preLaunchTask": "g++ build active file",

解决方案:

将task.json的这个配置:

"label": "C/C++: g++ 生成活动文件",

修改为:

"label": "g++ build active file",

----------------------------------------------下面可以忽略----------------------------------------------------

只要它两的值一样就行。你完全可以该成这个样子:(没错,我就是改成这个样子的)

"label": "g++ build active file  hahaha",

参考连接:

配置环境:https://code.visualstudio.com/docs/cpp/config-linux

问题解决:https://stackoverflow.com/questions/59106732/visual-studio-code-debugger-error-could-not-find-the-task-gcc-build-active-f

posted @ 2021-06-09 11:13  dlage  阅读(124)  评论(0编辑  收藏  举报  来源