I am new to C++ and VS Code.
I am trying to debug my C++ code in VS Code using g++.
But I got this error message: The preLaunchTask 'C/C++:g++.exe build active file' terminated with exit code -1.
This is my code:
/*blabla*/
This is my 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"
}
]
}
This is my 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"
}
]
}
This is what is in my Terminal:
> 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.
I could debug code successfully yesterday. Then I installed git and SSH (not sure if this is relevant, but including it just in case).
Today, I tried to debug code, but I can no longer do it successfully.
I tried to google the error message but could not figure out the problem.