visual studio code无法生成可执行文件

配置visual studio code c++ 环境出现无法生成可执行文件问题(另看)

问题描述

visual studio code 无法生成可执行文件(*.exe),报错The prelaunchTask 'g++ builder' terminated with exit code -1.

1. 前置条件

  1. 安装visual studio code
    下载很慢或者下载失败的,请转到我上传的文件
  2. 安装MinGW
  3. Path配置
  4. 安装c++ extension

2. 测试环境

  1. gcc
gcc -v

Using built-in specs.
COLLECT_GCC=D:\ProgramFiles(x86)\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=d:/programfiles(x86)/mingw/bin/…/libexec/gcc/mingw32/9.2.0/lto-wrapper.exe
Target: mingw32
Configured with: …/src/gcc-9.2.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-static --enable-shared --enable-threads --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libgomp --disable-libvtv --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --disable-build-format-warnings --prefix=/mingw --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --enable-nls --with-pkgversion=‘MinGW.org GCC Build-2’
Thread model: win32
gcc version 9.2.0 (MinGW.org GCC Build-2)

  1. g++
g++ -v

Using built-in specs.
COLLECT_GCC=D:\ProgramFiles(x86)\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=d:/programfiles(x86)/mingw/bin/…/libexec/gcc/mingw32/9.2.0/lto-wrapper.exe
Target: mingw32
Configured with: …/src/gcc-9.2.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-static --enable-shared --enable-threads --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libgomp --disable-libvtv --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --disable-build-format-warnings --prefix=/mingw --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --enable-nls --with-pkgversion=‘MinGW.org GCC Build-2’
Thread model: win32
gcc version 9.2.0 (MinGW.org GCC Build-2)

  1. gdb
gbd -v

GNU gdb (GDB) 7.6.1
Copyright © 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “mingw32”.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.

3. visual studio code 配置c++环境(解决办法)

  1. c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}\\**",
                "d:\\programfiles(x86)\\mingw\\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\include\\c++",
                "d:\\programfiles(x86)\\mingw\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32",
                "d:\\programfiles(x86)\\mingw\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\backward",
                "d:\\programfiles(x86)\\mingw\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\include",
                "d:\\programfiles(x86)\\mingw\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\..\\..\\..\\..\\include",
                "d:\\programfiles(x86)\\mingw\bin\\..\\lib\\gcc\\mingw32\\9.2.0\\include-fixed"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\ProgramFiles(x86)\\Mingw\\bin\\g++.exe",
            "intelliSenseMode": "windows-gcc-x86",
            // "cStandard": "c17",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}
  1. lauch.json
{
    // 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) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\ProgramFiles(x86)\\MinGw\\bin\\gdb.exe",
            "preLaunchTask": "g++ builder",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }

    ]
}
  1. tasks.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "process",
			// "type": "cppbuild",
			"label": "g++ builder",
			"command": "D:\\ProgramFiles(x86)\\Mingw\\bin\\g++.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe"
			],
			"options": {
				"cwd": "D:\\ProgramFiles(x86)\\Mingw\\bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": "test",
			"detail": "编译器: D:\\ProgramFiles(x86)\\Mingw\\bin\\g++.exe"
		}
	]
}

注意第一行type属性默认为cppbuild ,结果报错The prelaunchTask 'g++ builder'terminated with exit code -1.我把它改为了process,问题解决。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑暗守护者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值