This question was migrated from Super User because it can be answered on Stack Overflow.
Migrated 15 days ago.
I am trying to write a very simple ncurses program, just to play around with, using mingw-w64 on Windows 10. I installed the mingw-w64-x86_64-ncurses package with pacman, and am using the MSYS2 MinGW64 environment terminal. I have no experience with any curses library and very little experience in general developing software on Windows.
I have written the following hello world program in Main.cpp:
#include <iostream>
#include <ncurses.h>
#include "Headers.hpp"
int main(int argc, char ** argv) {
initscr();
printw("Hello World!");
refresh();
getch();
endwin();
return 0;
}
I compile this with the following command:
g++ -I /C/msys64/mingw64/include/ncurses HelloWorld.cpp -L/C/msys64/mingw64/bin -lncursesw6 -o main
It compiles, but when I run main.exe, I get
Error opening terminal: xterm.
Why does this happen, and how can I fix it?
The MInGW build works for Windows console (see README.MinGW). Other platforms use $TERM. msys2's mingw32 and mingw64 configurations are used for targeting the Windows console. Use the msys2 configuration if you want a program to work in that configuration.
The Windows Console API uses function-calls rather than writing characters (and escape sequences). This is different from mintty (used in msys2), xterm, Windows Terminal.
Further reading:
Using the Console
Console Functions (Windows Console API)
I had similar problem using the ucrt64 environment on msys2. Seems the proper configuration for xterm can not be found. Try:
export TERM=xterm
export TERMINFO=<path_to_ncurse_build>/share/terminfo
./my_program.exe
It should work. Have good coding!!!
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.
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.
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.
I'm using Windows 7 64bit.
I installed eclipse version 3.6.2, cdt, and MinGW. I have a C++ console program in Eclipse as follows:
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
setbuf(stdout, NULL);
for (int i = 0; i < 10000000; i++) {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
}
int val;
cin >> val;
return 0;
}
If I run this console program, it should display Hello world to Console View in Eclipse, but nothing displays.
If I go to the debug folder and run the exe, it does print to the console.
If I make some syntax mistake, then the Eclipse Console View will show something, such as:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hh.o ..\src\hh.cpp
..\src\hh.cpp: In function 'int main()':
..\src\hh.cpp:17:3: error: expected ';' before 'return'
Build error occurred, build is stopped
Time consumed: 255 ms.
Why is nothing showing in the Eclipse console view and how can I make my C++ console program display output?
I found a workaround from this site:
http://www.eclipse.org/forums/index.php?=42e862594001fa4469bbc834885d545f&t=msg&th=197552
At that link, look at the reply from "No real Name".
In case the link goes down, here is the content:
Environment: jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit
No console output at "Run", but output correctly at "Debug".
The following method worked for me:
1. Goto Project->Properties->Run/Debug Settings, choose the .exe file
and press "Edit"
2. In the "Environment" tag, press "New", set it as:
"Name:PATH"
"Value:C:\MinGW\bin"
In fact, I have already set "C:\MinGW\bin" in windows PATH environment
variable, but it seemed to not work.
The problem is that your program uses dll libraries from MinGW - try to start the exe file manually, it will report some error about missing dlls.
Solution can be, that you copy required dlls to .exe file in your project directory (and Release or Debug subdirectory, depends on what .exe are you executing with Run command).
Or, in menu Run -> Run Configuration select the configuration which you use for that .exe file (or create a new C/C++ Application configuration) and select Environment tab in the right panel. There add new variable named PATH with value c:\MinGW\bin (this is default path to mingw\bin directory, use a path valid for your instalation if it's somewhere else)
Edit: Now I'm looking at post by Vikyboss and it's in fact the same - setting the PATH variable in Run configuration. Setting PATH variable in Preferences > C/C++ (Expand it) > Environment as described by Sydraps didn't work for me.
But I think that static linking that libraries may be the best solution for you. In menu Project -> Properties select C/C++ Build -> Settings. In the right panel select Configuration which you want to change (you may select All). In the tab Tool Settings select MinGW C++ Linker -> Miscellaneous and in the right panel in the Linker flags type -static. Now the .exe will be bloated by the size of the libraries (in my case approx. +900kB for Hello world example, requiring 2 dlls), but it will be independent at any libraries.
I hope this will be helpful for anyone trying to start with Eclipse C/C++ and wondering why there's no Hello world in console.
Ales Chlubny
I fixed the problem on my windows 7 x64 PC. In the Eclipse window go to Preferences > C/C++ (Expand it) > Environment > Add:
"Name:PATH"
"Value:C:\MinGW\bin"
If this does not fix it. Try adding the above to the system environment variables on your PC in Computer > Advanced System settings
I find the reason, just because I'm using 64bit eclipse!
I turn to 32 bit eclipse, the same code works fine.
My problem with displaying hello world(64 bit Windows7) in console was solved when I ran eclipse as administrator.
I added the C:\MinGW\bin to environment variable path and then started eclipse as administrator
I created a Hello World C++ Project (MinGW GCC) app from the Eclipse wizard, cut and pasted your code and it compiled fine. Then prior to running I reduced your loop to 10 and it ran fine.
You don't say how you created your project but it would appear likely your missing some include directive or library path. Also I don't see the need to include or setbuf(stdout, NULL). I also find it helpful when troubleshooting to NOT bring an entire namespace into scope. Rather do this:
using std::cout;
using std::cin;
Finally, flushing the buffer each time with << endl; seems like overkill, adding a simple \n to the end of the string would be more efficient.
(I did all this on Win 7 64 bit - but I was using a 32 bit version of Eclipse Galileo)
If you are using MinGW compiler,
Add -static-libgcc -static-libstdc++ as Linker flags for your new
project. This text should be added to the Linker flags field, which
can be found by right-clicking on the new Project in the Project
Explorer and clicking on Properties. Under the Project Properties,
expand the C/C++ Build menu and click on Settings. Under the Tool
Settings tab, expand the MinGW C++ Linker menu and click on
Miscellaneous. Add the text to the Linker flags field, then click the
Apply button.
http://orfe.princeton.edu/help/article-296
For me installing the 32 bit versions of Eclipse (Indigo 3.7) and the 32 bit Java JDK/JRE did not work. I use the much quicker solution from the Eclipse CDT/User/FAQ:
Quote from Eclipse CDT/User/FAQ - Eclipse console does not show output on Windows:
Eclipse console does not show output on Windows In Eclipse CDT on
Windows, standard output of the program being run or debugged is fully
buffered, because it is not connected to a Windwos console, but to a
pipe. See bug 173732 for more details. Either add fflush calls after
every printf or add the following lines in the start of the main
function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
I had an issue with my eclipse-cdt, new C++ project > hello world (cygwin gcc), right click on exe file, run as and nothing was showing on console. It was the same with c project.
I saw that my eclipse version was already a 32bits one.
I figured this out and here is (the) my solution:
There are several compilation profiles in eclipse cdt: release and debug. The default profile in eclipse cdt is debug. So, launching exe using "run as" does not work, you should launch it using "debug as". In my case, I was using a really recent cygwin installation with gcc installed, but with gdb not yet installed. I had to install gdb package in cygwin using cygwin-setup. I reran the exe using "debug as" and it worked.
I guess using release profile instead of default debug profile, rebuilding also works, and I guess that it's the same with mingw environment.
Just added the C:\MinGW\bin to environment variable 'Path' in Windows 7 64-bit.
Now Console outputs messages
I encountered a similar problem.
Environment:
jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit
No console output at "Run", but output correctly at "Debug".
The following method worked for me:
Go to Project > Properties > Run/Debug Settings
Choose the .exe file and press "Edit"
In the "Environment" tag, press "New", set it as:
"Name:PATH"
"Value:C:\MinGW\bin"
In fact, I have already set "C:\MinGW\bin" as the Windows PATH environment variable, but it seemed to not work.
Works for me by going Administator on Eclipse Kepler 64bit.
In case someone is interested, I found how to fix it forever on Windows XP (may work in other windows version though) without you having to specify the variables of each executable and such:
Start Menu > RightClick on MyComputer > Properties > Advanced Options > Environment Variables
There, in the "User variables" field,
If there's an environment variable called PATH, select Modify and add this information in the end of the Value field, separated by semicolon:
C:\MinGW\bin
Example:
C:\SomeDirectory; C:\Another; C:\MinGW\bin
If the environment variable PATH does not exist, add a new one with this information:
Name: PATH
Value: C:\MinGW\bin
Accept all and you should get console output :)