c++ - 错误:preLaunchTask 'C/C++:g++.exe build active file' 以退出代码 -1 终止
问题描述
我是 C++ 和 VS Code 的新手。
我正在尝试使用 g++ 在 VS Code 中调试我的 C++ 代码。
但我收到此错误消息: preLaunchTask 'C/C++:g++.exe build active file' 以退出代码 -1 终止。
这是我的代码:
/*blabla*/
这是我的tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\usr\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\msys64\\usr\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\msys64\\usr\\bin\\g++.exe"
}
]
}
这是我的launch.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": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\msys64\\usr\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\usr\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
这是我的终端中的内容:
> Executing task: C/C++: g++.exe build active file <
Starting build...
Build finished with errors(s):
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/libmsys-2.0.a(libcmain.o): in function `main':
/c/_/S/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
/c/_/S/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x86): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
The terminal process terminated with exit code: -1.
Terminal will be reused by tasks, press any key to close it.
> Executing task: C/C++: g++.exe build active file <
Starting build...
Build finished with errors(s):
/usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../x86_64-pc-msys/bin/ld: /usr/lib/gcc/x86_64-pc-msys/10.2.0/../../../../lib/libmsys-2.0.a(libcmain.o): in function `main':
/c/_/S/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
/c/_/S/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x86): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status
The terminal process failed to launch (exit code: -1).
Terminal will be reused by tasks, press any key to close it.
我昨天可以成功调试代码。然后我安装了 git 和 SSH(不确定这是否相关,但包括它以防万一)。
今天,我尝试调试代码,但我无法再成功。
我试图用谷歌搜索错误消息,但无法找出问题所在。
解决方案
推荐阅读
- php - 未收到来自联系表的电子邮件
- c - 使用 #include 将动态生成的 .txt 文件合并到 .ino 文件中
- python - Python 只使用一个核心
- c - C - 当其他线程修改值时,输出线程应更新
- javascript - 如何将单个数组转换为多个嵌套数组格式以供切片方法使用
- node.js - 在同一台机器上运行多个唯一的 nodejs 网络服务器
- django - 如何基于一个字段从 Django 模型调用 API
- javascript - 字母数字/自然对 Javascript 中带有前导零的数组进行排序
- sql - HSQLDB - 只读模式不获取应用程序插入的最新记录
- freeradius - Freeradius 允许来自特定站点的用户 (WISPr-Location-ID)