專案場景:
環境: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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/286666.html
標籤:區塊鏈
