VSCode 报错:GDB failed with message:“path : not in executable format: File format not recongnized.

报错信息

在这里插入图片描述

在这里插入图片描述

个人配置

VSCode + TDM-GCC-64(5.1.0)
在这里插入图片描述

找问题

0 路径没有中文

1 生成exe可执行文件没问题

PS D:\vscode\cpp\sort> g++ quicksort.cpp -o quicksort
PS D:\vscode\cpp\sort> ./quicksort.exe
排序后的数组为:
3 11 11 13 13 17 17 23 26 45 72 89
请按任意键继续. . . 

quicksort代码

// Quick_Sort.cpp : Defines the entry point for the application.
// 快速排序算法
 
#include<iostream>
using namespace std;
 
//快速排序算法(从小到大)
//arr:需要排序的数组,begin:需要排序的区间左边界,end:需要排序的区间的右边界
void quickSort(int *arr,int begin,int end)
{
    
    
	//如果区间不只一个数
	if(begin < end)
	{
    
    
		int povit = arr[begin]; //将区间的第一个数作为基准数
		int i = begin; //从左到右进行查找时的“指针”,指示当前左位置
		int j = end; //从右到左进行查找时的“指针”,指示当前右位置
		//不重复遍历
		while(i < j)
		{
    
    
			//当右边的数大于基准数时,略过,继续向左查找
			//不满足条件时跳出循环,此时的j对应的元素是小于基准元素的
			while(i<j && arr[j] > povit)
				j--;
			//将右边小于等于基准元素的数填入右边相应位置
			arr[i] = arr[j];
			//当左边的数小于等于基准数时,略过,继续向右查找
			//(重复的基准元素集合到左区间)
			//不满足条件时跳出循环,此时的i对应的元素是大于等于基准元素的
			while(i<j && arr[i] <= povit)
				i++;
			//将左边大于基准元素的数填入左边相应位置
			arr[j] = arr[i];
		}
		//将基准元素填入相应位置
		arr[i] = povit;
		//此时的i即为基准元素的位置
		//对基准元素的左边子区间进行相似的快速排序
		quickSort(arr,begin,i-1);
		//对基准元素的右边子区间进行相似的快速排序
		quickSort(arr,i+1,end);
	}
	//如果区间只有一个数,则返回
	else
		return;
}

int main()
{
    
    
	int num[12] = {
    
    23,45,17,11,13,89,72,26,3,17,11,13};
	int n = 12;
	quickSort(num,0,n-1);
	cout << "排序后的数组为:" << endl;
	for(int i=0;i<n;i++)
		cout << num[i] << ' ';
	cout <<" "<<endl;
	system("pause");
	return 0;
}

2 修改tasks.josn

在这里插入图片描述
只改了这一个地方!!!就可以了!!! label 后面的值不改也行

解决

在这里插入图片描述

配置文件

c_cpp_properties.json

{
    
    
    "configurations": [
        {
    
    
            "name": "Win32",
            "includePath": [
                "D:/TDM-GCC-64/include",
                "D:/TDM-GCC-64/x86_64-w64-mingw32/include",
                "D:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
                "D:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "D:/TDM-GCC-64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
            
        }
    ],
    "version": 4
}

launch.josn

{
    
    
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "C++ Launch (GDB)",    // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",              // 配置类型,这里只能为cppdbg                        
            "request": "launch",           // 请求配置类型,可以为launch(启动)或attach(附加)
            "targetArchitecture": "x86",   // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
            // 要进行调试的可执行文件的路径               
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
            // gdb调试器路径,这里选择TDM-GCC安装目录下的gdb
            "miDebuggerPath":"D:/TDM-GCC-64/bin/gdb64.exe",             // miDebugger的路径,注意这里要与MinGw的路径对应。64位系统用gdb64.exe
            "args": [],                                                 // 程序调试时传递给程序的命令行参数,一般设为空即可        
            "stopAtEntry": false,                                       // 设为true时程序将暂停在程序入口处,我一般设置为true
            "cwd": "${workspaceRoot}",                                  // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
            "externalConsole": true,                                    // 调试时是否显示控制台窗口,一般设置为true显示控制台
            // 调试会话前执行的任务,这里是task.json中配置好的编译任务
            "preLaunchTask": "g++",                                     // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
            // pretty-printing配置,可以直观打印出C++中的容器
            "setupCommands": [
                {
    
    
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}

tasks.json

{
    
    
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileBasenameNoExtension}.exe"
    ],
    "problemMatcher": {
    
    
        "owner": "cpp",
        "fileLocation": [
            "relative",
            "${workspaceRoot}"
        ],
        "pattern": {
    
    
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "tasks": [
        {
    
    
            "type": "cppbuild",
            "label": "C/C++: cpp.exe 生成活动文件",
            "command": "D:\\TDM-GCC-64\\bin\\g++.exe", //改为g++.exe
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
    
    
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
    
    
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}

settings.json

{
    
    
    "files.associations": {
    
    
        "atomic": "cpp",
        "bit": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "compare": "cpp",
        "concepts": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cwchar": "cpp",
        "exception": "cpp",
        "initializer_list": "cpp",
        "ios": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "iterator": "cpp",
        "limits": "cpp",
        "memory": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "typeinfo": "cpp",
        "utility": "cpp",
        "xfacet": "cpp",
        "xiosbase": "cpp",
        "xlocale": "cpp",
        "xlocinfo": "cpp",
        "xlocnum": "cpp",
        "xmemory": "cpp",
        "xstddef": "cpp",
        "xstring": "cpp",
        "xtr1common": "cpp",
        "xutility": "cpp"
    }
    
    
}

猜你喜欢

转载自blog.csdn.net/qq_41398619/article/details/127035622