Mingw runtime error - c++

I'm a new user of MinGW, and I have already run into problems. When attempting to compile a very simple Hello world c++ program, I get an error. I type the command:
g++ hello.cpp -o hello.exe
and then I get the message dialog:
Microsoft Visual C++ Runtime Library
Runtime Error!
Program: c:\mingw\bin\...\libexec\gcc\mingw32\4.8.1\cc1plus.exe
R6034:
An application has made an attempt to load the C Runtime library incorrectly.
Please contact the application's support team for more information.
followed immediately by this message dialog:
cc1plus.exe - Program error
The application failed to initialize properly
(0xc0000142). Press OK to close application.
And then the usual junk about Windows finding a solution online.
I used the automatic installer mingw-get-setup.exe and simply followed the instructions. I chose the installation folder to be C:\mingw, and in the MinGW Installation Manager, I chose to install mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, mingw32-gcc-objc and msys-base. As suggested in the installation guide, I added PATH in the Environment Variables.
The code I was trying to compile was:
#include <iostream>
using namespace std;
int main(int argc, char ** argv){
cout << "hello world" << endl;
return 0;
}
I also tried to compile a similar ANSI-C code with the command:
gcc hello.c -o hello.exe
and I got the same error.
I tried the command in cmd.exe as well as in MSYS and got the error in both cases. My operating system is Windows Vista Home Premium, and I have Microsoft Visual C++ 2010 installed on it. I mention this because I tried to do the same installation on a windows 7 computer without VC++ and here the compiler worked without problems. Does this mean that you can't have MinGW and VC++ on the same computer?

The problem was, as suggested in the comments, that programs other than the Gnu Compiler had left values in the %PATH% variable. What I did not initially notice, was the fact that there are two %PATH% variables, one for the user and one for the system, and both can interfere with the MinGW installation.
The system %PATH% variable contains (at least on my PC) quite a lot of entries and removing all of them might not be a good idea. In my case, however, it was sufficient to remove entries from MatLab and Texnic Center. Afterwards, g++ and gcc worked flawless.

Related

Why code::blocks shows problem during compilation of C++ file

I installed code::blocks before but I have never encountered a problem during the execution of a hello world program, which everyone must be familiar of. Today, I installed code::blocks along with GNU compiler and added it to PATH (environment variable). Everything seems right, but when I run the below code, it showed an error:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
(I build and run the code and the messages are as follows)
Project/Target: "FileTest - Debug":
The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
Probably the toolchain path within the compiler options is not setup correctly?!
Do you have a compiler installed?
Goto "Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.
Tried to run compiler executable 'C:\MinGW/bin/gcc.exe', but failed!
Skipping...
Nothing to be done (all items are up-to-date).
I don't quite know what this log meant. I installed MinGW and when I went to Settings / Compiler, it just showed that I am using MinGW. Everything seems right.
Here is a screenshot from my editor:
https://i.stack.imgur.com/xdKCT.png.
Anyone help me?
It says the code::blocks can't find the compiler. So, naturally it will be invalid. Try uninstalling the code::blocks IDE & from the site of code::blocks install the minGW setup. I am giving this link, see it works or not.
https://sourceforge.net/projects/codeblocks/files/Binaries/20.03/Windows/codeblocks-20.03mingw-setup.exe/download
I had the same error, It was a Environment error,
Download the mingw-setup.exe file from Code::Blocks ide.
Install
Go to Settings -> Compiler -> Reset Defaults

Facing "the application was unable to start correctly 0xc00007b." after i compiled my code with g++ compiler on command prompt in Windows 10

I compiled a simple "Hello World" C++ code in command prompt (Windows 10), and then tried to run a.exe file, but got this well known error. Then I created a project in VS2019, and was able to run same code without any problem. Upon doing ldd a.exe all the dependent dlls were inside "/cygdrive/c/WINDOWS/SYSTEM32", so i copied executable over there, but still faced the same issue.
I also tried running in administrator mode, changing/troubleshooting the compatibility option to Windows 7/8 but none of them worked.
A couple of months back I was able to compile and run a code in this manner, but since then many software have been changed, so I kind off lost track which software change can cause this issue.
g++ -v ==>
Target: x86_64-w64-mingw32
{Several configurations}...
Thread model: win32
gcc version 4.6.3
Is there some common solution which I can try?

G++ fails to compile Win7, 64bit (MinGW.org GCC-6.3.0-1)

G++ fails to compile simple "Hello World" code.
Platform details are in the Title
I have tried to run from both VS Code ("insiders" version 1.26.0), and from the Windows command-line /terminal.
Neither route will return an *.exe file
This is the C++ code. VSCode Intellisense doesn't show any errors (C++17)
#include <iostream>
using namespace std;
int main()
{
std::cout << "Fresh New World" << std::endl;
return 0;
}
At the Windows command line (terminal) I've used the command
g++ -o FreshWorld.exe FreshWorld.cpp
This command does not return an error, nor does it return the desired *.exe file (I've even resorted to SEARCHing all the folders)
Running this in VSCode (1.26.0) also does not return an error.
I had run this code in the previous stable release (pre- "June 2018") VS Code, and it compiled properly. The problems started immediately after the update to Jn2018. I've worked with VS Code developers (that's why I'm running the "insiders" version) but, as we now know, the problem also exists at the command-line (terminal) so not confined to VS Code.
Any ideas??????
I am entire newbie to C++, MinGW, and to VS Code so this has become an insurmountable hurdle to further experimentation and learning!
Lots of things could be causing this:
Antivirus: it could be intercepting the gcc executable (they tend to dislike other compilers due to the way a compiler generates executable code etc.). Try disabling the antivirus and test again.
Your MinGW(-w64) installation is broken. Try reinstalling. Where are you getting your GCC? I strongly suggest using something like the official MinGW-builds for MinGW-w64 here or a package management system such as MSYS2.
Wrong environment settings. Your provide little details of how and what you are doing (how are you starting the command prompt interpreter, how is your PATH set up, etc.).
Without more details, I can't determine what is going wrong for you. Please edit your question to provide these details.

mingw32: all compiled executables hang

I've just installed the most recent version of mingw32 and trying to compile even a hello world c++ program fails.
Installation was in the default C:/MinGW directory. I chose the option to install with mingw-get gui, and I selected the Basic Setup tab on the left-hand column, marked the mingw32-base and mingw32-gcc-g++ options for installation. Then I applied changes and downloaded all the files. Lastly I added C:/MinGW/bin to the path of windows.
Now I create a file that looks like this:
test.cpp:
#include <iostream>
int main() {
std::cout << "hello world!" << std::endl;
return 0;
}
and then I compile with g++ test.cpp
Now, the problem is a bit harder to diagnose. When I execute the output a.exe file, the command line simply hangs, no output, no return. If I try and cancel execution with ctrl-c, nothing happens. When I forcefully exit out of the command line, and try to delete a.exe, windows tells me the executable is currently opened by system, and the only way to forcefully remove the file is with FileASSASSIN.
Some notes, I have visual studio 12 installed, but nothing pertaining to it in the path. I had a previous installation of cygwin64 but it has been removed entirely. I get the same behavior running it from powershell, normal command line, or Console2. Google suggested I try statically linking libstdc++ with -static-libstdc++ to no avail.
Also, when compiled with debugging symbols and then ran with gdb a.exe, and then you run start, it also hangs just the same.
I'm out of ideas on getting information for troubleshooting here. Does anyone have any insight?
On the suggestion of #M.M, I discovered that avast antivirus was the silent cause of halting any executables made by mingw32. This was puzzling, because I was running executables made by visual studio on command line only a few hours ago.
The lesson: If you encounter unexpected behavior, always try your antivirus.

MinGW w64 windows library eclipse (app crash)

I'm trying to get C++ working properly in Eclipse but it seems that anything except the normal MinGW is failing and I have no idea what I'm doing.
Reason I'm trying this is because MinGW complains about to_string() not existing in the std library and I've read that this was fixed in MinGW-w64.
I've downloaded MinGW and MinGW-w64 to separate folders, currently MinGW is included in PATH.
When I change my project properties [C/C++ Build -> Environment] variables to go with MinGW-w64 the stuff still builds but crashes when I try to run it.
I'm trying to build a win32 app (#include <windows.h>)
Flags in [C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous]: -c -fmessage-length=0 -std=c++11 -mwindows
I've also included a Pre-build step: windres ../src/resources.rc -o ../Resources/resources.o
And for some reason it compiles without error, but when I try to run the binary.exe it just crashes (which it didn't with normal MinGW).
I've also looked into Cygwin but I have no idea what packages to download and I can't even find the std library, let alone the windows library, in the massive massive list of installable packages.
I also don't want to use Visual C++ because that requires you to install Visual Studio (an IDE I loathe because of reasons(yes, multiple))
I'm doing the minor "Games Programming" and my school is giving us a crash-course C++ (which exists of six 3 hour long lessons to get a grasp of the basics) to use in building a simple game application. Problem is the teachers are Visual Studio fanboys and don't really know anything outside of that environment (most of 'em don't really seem to care either for that matter).
I'm having a lot of trouble setting this up with no prior experience in C++ and a very janky C++ support for windows. ( I do know my fair share of Java (in Eclipse) and a bit of C# )
I've been searching for at least an hour without any results.
If I forgot to write down stuff or am being a total idiot here please do enlighten me.
Any help is much appreciated
Edit: I'm suddenly getting other error output <- forgot to clean before building
Edit edit: the error:
(hi is the icon)
Another Edit:
if I debug it breaks at No source available for "main() at 0x4081a9" which makes sense because I didn't make that kind of main because I'm writing a windows app. if I press continue it runs (what?) but then when I close it I see the following output:
C++ Win32.exe
~"[Inferior 1 (process 7012) exited normally]
"
gdb
[New Thread 7012.0x1d14]
Temporary breakpoint 1, 0x00000000004081a9 in main ()
Quit (expect signal SIGINT when the program is resumed)