VSCode is displaying the error message
ERROR: During startup program exited with code 0xc0000135.
When I try to debug the code. Initially MinGW installation was showing the error missing dll files, then I reinstalled MinGW, now it is no more showing any errors and the catalogue is updating properly. Restarted the system, re-added the bin folder to the Environment Path Variable.
The file is being compiled and executing properly, the Error message is displayed only while debugging
IDE: VSCode
Compiler: MinGW
OS: Windows
Tried Fixes:
Reinstalled MinGW
Added the bin folder to the environment path variables
Restarted VSCode
launch.json for VSCode:
{
"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": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\C++\\minGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
Code:
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
}
Related
I have had some random chances with debugging a c++ code inside visual studio code using the g++/gdb. Usually when I right-click on a file and select Build and Debug active file, it works
For the current scenario I am getting the following error :
In the Debug console I see the following error :
The program '/mnt/c/D-drive/a.out' has exited with code 1 (0x00000001).
This is my launch.json file
{
// 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++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "/mnt/c/D-drive/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I generated the a.out file using the command g++ a1q2tester.cpp timer.cpp -std=c++0x
I have put breakpoints inside the a1q2tester.CPP file. Not sure what could be going wrong. The program just stops abruptly, and no breakpoint is triggered.
Overview
I have been trying to get C++ debugging to work in VS Code for quite some time now with no success.
I followed the official guide from Microsoft on setting up debugging in VS Code, but still ran into problems.
For context:
VS Code config files
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": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The issue
The problem branches out into two parts.
1. Firstly, I normally use git bash as my default shell in Windows, and would like to keep it that way when debugging C++. However, something that seems to be specific to it is an issue with paths. It seems that running the task here leads to the shell ignoring slashes between directories (likely because of the disparate file system interpretations). This can be seen in the following example:
> Executing task: 'C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g C:\Users\Redact\Desktop\code\Competitive_Programming\Evaluation.cpp -o C:\Users\Redact\Desktop\code\Competitive_Programming\Evaluation.exe <
g++.exe: error: C:UsersRedactDesktopcodeCompetitive_ProgrammingEvaluation.cpp: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
The terminal process "C:\Program Files\Git\bin\bash.exe '-c', ''C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g C:\Users\Redact\Desktop\code\Competitive_Programming\Evaluation.cpp -o C:\Users\Redact\Desktop\code\Competitive_Programming\Evaluation.exe'" terminated with exit code: 1.
2. When running the debugger with either PowerShell or cmd as the shell, pre-build works as intended and a debugging session is opened, but nothing else happens. The code doesn't stop in the main function (as the guide stated it should) nor are any breakpoints hit—indicating it's not running at all:
(Click Here to see moving gif if it appears still here)
Any help is very much appreciated.
When debugging a cpp file in Visual studio code the launch.json seems to be making a launch.exe even though I specified in the tasks that the output file should be called "main.exe" and on top of that there's a build error yet the executable made runs correctly.
All files are in the same directory and the only folder in this directory is the automatically generated .vscode folder
My task.json :
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\main.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {"kind" : "build","isDefault": true},
"detail": "compiler: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe\""
}
]
}
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}\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
And then the actual cpp files :
main.cpp
#include "Log.h"
int main()
{
Log("Hello World");
}
Log.cpp
#include "Log.h"
#include <iostream>
void Log(const char* message)
{
std::cout << message << "!\n";
}
And a header file
Log.h
#pragma once
void Log(const char* message);
What I expect to happen is that the tasks.json gets all the cpp files compiled and linked then creates an executable called main.exe.
This does happen when I just run the build task through Terminal > Run Build Task... but when I try debugging by pressing F5 when on my main.cpp file, there is a build error and, in my directory, a launch.exe executable is created. I am then prompted that there were build errors and after clicking "debug anyway", a prompt appears showing that "main.exe" does not exist.
The build error :
C:\Users\Me\AppData\Local\Temp\ccUAuPNe.o: In function `main':
c:/Users/Me/Projects/test/main.cpp:7: undefined reference to `Log(char const*)'
collect2.exe: error: ld returned 1 exit status
The terminal process failed to launch (exit code: -1).
My platform is windows and
I believe I have all the necessary extensions installed correctly so I don't really understand what causes this issue.
It does debug correctly when I change the "program" value in launch.json to "${fileDirname}\launch.exe" (although there is still the build error) but why is launch.exe being made and why are there build errors when debugging but no build errors when going through Terminal > Run Build Task... ?
I am new to C++ and vscode. I know how to run the vscode debugger on a single .cc file but I don't know how to run it on a folder with multiple .h and .cc files (I have Makefile and linking is working). My current solution is to copy and paste the entire project into one file and then run the debugger which is very inefficient.
I suspect that I have to modify launch.json, so here is mine. Any tips are appreciated!
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
I usually store all my programming files in One Drive so that I can access them anywhere I go. But now I need to be able to compile my c++ programs on Linux machines. So I tried using visual studio code in WSL mode but when I try to compile and debug my code I am told that it can't find any *.cpp fies in the specified location, yet the files are clearly there. If I run the compile command on my own in the ubuntu window it works just fine. When I moved the files from /mnt to my home directory everything worked fine. Why would my compile command work just fine when I use it from the ubuntu window, but now work when VS Code tries to do it? Any ideas?
Here is my task.json file and launch.json file:
task.json
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${cwd}/*.cpp",
"-o",
"${cwd}/main"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${cwd}/main",
"args": ["test1.txt"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}