'VS code c++: "exited with code=3221225785"
I'm a complete novice to VS code, and I've only been coding with C++ for around a month. I tried this bare bones program to make sure things were set up correctly:
#include <iostream>
#include <vector>
using namespace std;
int main() {
cout << "Hello world" << endl;
vector<int> v;
return 0;
}
Nothing shows up when running the executable. Removing the vector declaration causes the program to run normally.
I did find this which encountered a similar problem with declaring a string, and the solution (static linking with -static-libstdc++) works for me, though the author who gave the solution wasn't entirely sure why it worked either.
However, since I'm a noob, I don't understand that well why static linking fixed my problem, even after reading this, and am worried about some of the drawbacks mentioned (it recommends only linking statically if you absolutely have to since disadvantages outweight advantages), so I was wondering if there was some other solution besides static linking.
EDIT: Clarification--the program's outputs now show up normally in terminal, but in the output window, the same exit code still appears.
Solution 1:[1]
Configure VSCode as given below for "VS Code C++ : exited with code=3221225785"
Install the Code Runner Extension of Visual Studio Code.
Open the Settings(Seetings.json).
Search "code-runner.executorMap" in the Search bar.
modify
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
to
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -static && $dir$fileNameWithoutExt",
After that Right Click on source code file select the option Run Code.
For DEBUG:
add an extra parameter "-static" in "args" of tasks.json file.
Before:
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
After:
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-static"
],
"- static" is static linking parameter when we compiling and running.
Solution 2:[2]
For me solved when I put the file libstdc++-6.dll on folder that I needed debug.
This file is in "\MinGW\bin".
Solution 3:[3]
I also encountered the same situation, due to the environment variable access error, because I installed MATLAB on my computer first,the environment variable D: matlab\bin also contains the libstdc++-6.dll link library, so the computer will first access D:\ matlab\bin instead of C: \mingw64\bin. So what we need to do is to move the C:\ mingw64\bin environment variable in front of the D:\ matlab\bin environment variable in the computer properties environment variable to solve this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ujjawal kumar |
Solution 2 | Fernando Silva |
Solution 3 | ??? |