报错:
-
目录结构
-
报错内容
-
问题所在
由于本人在一个工作路径上,创建了多个子文件夹,那么编译器无法按照文件夹来进行编译和链接,因此需要修改task.json文件中的args参数
解决办法:
- task.json文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\MinGW\\bin\\g++.exe",//前面的路径改成你安装的路径
"args": [
"-g",
// "${file}", //注释掉fiel修改成文件空间目录下的子目录
"${workspaceFolder}/Queue_implement/*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\MinGW\\bin"//前面的路径改成你安装的路径
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\MinGW\\bin\\g++.exe",//前面的路径改成你安装的路径
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
- launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",//前面的路径改成你安装的路径 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "task g++" } ] }
- c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "D:/MinGW/bin/g++.exe", //编译器路径 "cStandard": "gnu17", "cppStandard": "gnu++11", "intelliSenseMode": "windows-gcc-x64" } ], "version": 4 }