mingw32: all compiled executables hang - c++

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.

Related

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.

My C++ program gets" ... .exe has stopped working" windows 7 error

I have written a C++ program in Visual Studio 2010. It builds and runs fine in the IDE (even when running without debugger, in Release mode). However, whenever I run the executable from the command prompt, I get an "... .exe has stopped working" error message.
How can I figure out what's causing it to crash? Do I have to include something else in the command line if I use additional libraries/headers? Are there errors that make it through the Visual Studio IDE, but cause problems when running the program on the outside?
I'm not including my code, because there's way to much of it...
Help is greatly appreciated.
If your program had been rendered in Debug mode, try rendering it in Release mode and then retry.
The problem was incomplete directories for the files I was loading. I neglected to check for a successful open or use try/catch. It was running fine in the IDE because the file directory was in a subdirectory of the working directory. When I tried to run it from the command prompt, the relative directory was no longer valid. I changed the filenames to their complete directories, and everything worked fine.

Mingw runtime error

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.

Can't run programs on my mac

I've been programming on windows for about three months now and when my computer finally died I bought a mac. I'm really happy with it except I can't figure out how to run my c++ programs.
On windows it would open up in command prompt so I figured it would do the same thing except with terminal.
After I write my programs (in Xcode) I can compile them and it'll tell me if there are syntax errors but the run and run related buttons are all Grey and unusable.
It's incredibly annoying that I can't see how the program that I put 4 hours into runs and even more annoying that I don't know if I've made a runtime error. Someone please help.
Thank you very much, James
Assuming that you're trying to write a program that you interact with on the command line, you want to create a "Command Line Tool" project, found under "Application" in the Mac OS X section of the New Project dialog. Choose "C++ stdc++" from the "Type" dropdown, as well. This will give you a main.cpp that should look familiar to you, with a "Hello, World!" sample.
Note that when you Run this program, it might appear to do nothing - You need to open the Console (from the Run menu, or shift+command+R) to see your output.
Xcode deals in projects. If you're just opening the source file, there is no project. Create a project with the files in it and Xcode should let you run it.
Alternately, you can just use G++ on the command line to compile your files and run the resulting executable there.
Try compiling from the terminal as stated above. The a.out file should be created, and should run as long as Xcode has been installed. It should work fine from the terminal, and point out any errors in the compiler's output.
To runs the a.out file, ensure you are in the files directory in terminal and type ./a.out