0

I am unable to run a code as simple as the following. Everything works fine if I am not working with strings. I get an error- exited with code=3221225785 in 2.131 seconds. I've tried updating my MinGw compiler. Does not work even if I use compile and run extension on vscode.

#include<iostream>
#include<string>
int main()
{
  std::string a="world";
  std::cout<<a;
  return 0;
}
John
  • 2,633
  • 4
  • 19
  • 34
MurphyCodes
  • 1
  • 1
  • 3
  • Possibly related? https://stackoverflow.com/questions/53808442/vs-code-c-exited-with-code-3221225785 – ChrisMM Jun 17 '20 at 16:16
  • Try ruling out Visual Studio Code by compiling your test application manually in a command prompt. And running it from the command prompt so VSCode is not involved at all. – drescherjm Jun 17 '20 at 16:17
  • As you mention MinGW, I assume you are on windows. So what might happen is that the compiler using the headers of MinGW and links again the c++ runtime library provided by the microsoft or the other way round. And those are not ABI compatible. – t.niese Jun 17 '20 at 16:17
  • I'm not entirely sure, but... In your compiler `bin` directory, find following `.dll`s: `libgcc...`, `libstdc++...`, `libwinpthreads...` (the names can wary upon compiler distribution) can copy them to the directory where your `.exe` is. – HolyBlackCat Jun 17 '20 at 19:13

2 Answers2

0

it is really frustating to handle your systems setup, especially if you want to start to learn coding. My rescue called: build system. I'm using cmake with this tutorial.

But first thing first, for your special question, what you'll need are following workspace:

working_directory
   |--build/
   |--src/test_code.cpp
   |--src/CMakeLists.txt

with your code (I name it test_code.cpp):

#include<iostream>
#include<string>
int main()
{
  std::string a="world";
  std::cout<<a;
  return 0;
}

and CMakeLists.txt:

cmake_minimum_required (VERSION 3.7)
project(testSomething)
add_executable(test test_code.cpp)

and run following in /build directory:

> cmake ../src
> make
> ./test

Of course you'll need to install cmake first. I think, directly using a build system in a tutorial helps you take care of your system setup, so usually those build system could find your installed compiler, linker etc. without you telling it explicitly. (So its a kind of vodoo magic :)).

dboy
  • 1,004
  • 2
  • 16
  • 24
0

enter image description here

I tried the same, but I'm getting proper results in the terminal. I think you have not added 'mingw' to the environmental path.

enter image description here