I installed msys2 and tried running a simple hello world c++ program
#include<iostream>
int main()
{
int a;
std::cout<<"Hello World!n";
std::cin>>a;
return 0;
}
when running the executable produced by g++.exe, the command prompt freezes for a bit and then the program exits with no output.
some findings:
The C alternative of the hello world works completely fine.
I tried this code:
#include<iostream>
#include<stdio.h>
int main()
{
int a;
printf("something somethingn");
std::cout<<"Hello Worldn";
printf("Exitn");
return 0;
}
and the output was:
E:Test>g++ main.cpp
E:Test>a
something something
E:Test>
System info:
Windows 10
Mingw-w64-ucrt toolchain
Solution I tried:
I tried installing some “distro” mentioned in this post
and it worked.
Using the argument “-static-libstdc++” also works.
But I want to know why was it not working before adding the argument. And what file do I need in order to build it “dynamically” or how do I shorten the command to compile statically.(I am satisficed with the solution in the post but wanna know more about the causes and the fix)
1