1 C++报错unable to start debugging.unexpected GDB output from command
解决方案,不要将文件夹放在含有中文名的文件夹中,有时候桌面也可能导致中文文件夹的报错
一、VScode中c/c++配置
vscode软件和mingw软件需要自己安装。
1、vs文件的配置
在代码文件目录下,创建一个.vscode文件夹
在.vscode中创建 c_cpp_properties.json , launch.json , tasks.json 三个文件
1、c_cpp_properties.json文件的配置,只需要修改compilerPath中的内容,为mingw当中g++.exe位置。
{
"configurations": [
{
"name": "Win64",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:/Mingw/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
2、launch.json文件的配置,只需要修改miDebuggerPath当中的内容,为mingw中gdb.exe的位置。
{
// 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",
"preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
"type": "cppdbg",//配置类型,只能为cppdbg
"request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
"args": [],//调试传递参数
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
"MIMode": "gdb",
"miDebuggerPath": "E:/Mingw/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3、tasks.json文件的配置。需要修改tasks当中的command,以及options当中的cwd;
command为mingw中g++.exe文件位置;options当中的cwd为mingw中bin文件位置。
注意,其中有一段是这样的
//注意:c语言或者c++文件一个项目中只能开一种,开了c语言文件编译,就得注释掉c++文件编译
“
w
o
r
k
s
p
a
c
e
F
o
l
d
e
r
∗
.
c
p
p
"
,
/
/
c
+
+
多
文
件
编
译
/
/
"
{workspaceFolder}\\*.cpp", //c++多文件编译 //"
workspaceFolder∗.cpp",//c++多文件编译//"{workspaceFolder}\*.c”, //c语言多文件编译
// “${file}”, //单文件编译,可以直接使用上面的
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file", //这里注意一下,见下文
"command": "E:\\Mingw\\mingw64\\bin\\g++.exe",
"args": [
"-g",
//注意:c语言或者c++文件一个项目中只能开一种,开了c语言文件编译,就得注释掉c++文件编译
"${workspaceFolder}\\*.cpp", //c++多文件编译
//"${workspaceFolder}\\*.c", //c语言多文件编译
// "${file}", //单文件编译,可以直接使用上面的
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "E:\\Mingw\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
文件如下:
2、vscode软件
1、打开文件夹
2、创建一个c文件,点击运行
这里的getchar();是防止调试框一闪而过的作用,当然也可以不用这个方法,直接在return 0这里设置一个断点就可以。
#include "stdio.h"
int main()
{
printf("好的");
getchar();
return 0;
}
在tasks.json中设置为c语言编译。
成功
3、创建一个cpp文件测试
#include "iostream"
using namespace std;
int main()
{
printf("cpp文件测试");
getchar();
}
在tasks.json中设置为c++编译
运行
成功。
3、编译多个头文件
1、创建需要的文件
比如有两个cpp和两个.h文件
main.cpp;max_min.cpp和main.h和max_min.h文件
1、main.cpp
#include "main.h"
using namespace std;
int main()
{
cout << acos(-0.263976);
aa();
}
2、main.h文件
#ifndef _MAIN_H
#define _MAIN_H
#include "iostream"
#include "math.h"
#include "max_min.h"
#endif
3、max_min.cpp文件
#include "max_min.h"
void aa()
{
printf("测试");
}
4、max_min.h文件
#include "stdio.h"
void aa();
4、vscode中文路径问题解决
当出现调试时
这是因为文件路径中有中文。
解决方法:
1、将代码文件放在纯英文路径下面。
2、电脑设置-》时间与语言 -》区域 -》其他日期、时间和区域设置 -》区域 -》管理 -》更改区域系统设置 -》
二、Devc++项目创建
文件-》新建-》项目-》