- 配置visual studio code c++ 环境出现无法生成可执行文件问题([另看](http://39.99.157.105/zunnajim/?p=239))
- 问题描述
- 1. 前置条件
- 2. 测试环境
- 3. visual studio code 配置c++环境(解决办法)
visual studio code 无法生成可执行文件(*.exe),报错The prelaunchTask 'g++ builder' terminated with exit code -1.
- 安装visual studio code
下载很慢或者下载失败的,请转到我上传的文件。 - 安装MinGW
略 - Path配置
略 - 安装c++ extension
略
- 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)
- 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)
- gdb
gbd -v
3. visual studio code 配置c++环境(解决办法)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/.
- 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
}
- 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
}
]
}
]
}
- 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
,问题解决。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)