3

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.

Evan G.
  • 31
  • 1
  • 3
  • Convert large numbers to hex before you google. "Entrypoint not found" tells you that there is a problem with the DLL you use, it does not match the #include directives in your program. Yes, static linking is a band-aid, you can't use the wrong DLL that way. VSCode right now is not exactly the best way to get started on C++, in is in preview and there are a lot of tricky things you have to get right. If you get just one small detail wrong then it is easy to get stuck badly. Do consider VS Community edition. – Hans Passant Dec 17 '18 at 08:54

3 Answers3

5

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.

ujjawal kumar
  • 51
  • 1
  • 2
4

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。

孙栋臣
  • 41
  • 1
3

For me solved when I put the file libstdc++-6.dll on folder that I needed debug.

This file is in "\MinGW\bin".