Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Compile Ncurses Program for Native Windows Use

I'm trying to compile a C program using Ncurses on Windows. I compiled it successfully using GCC and it works perfectly if I run it in Cygwin or MSYS2. However, if I try to run it in the Windows Command Prompt, I get this error:

Error opening terminal: xterm-256color.

Is it possible to compile it to run using the native Windows console? This is how I've been compiling it:

gcc -o PROGRAMNAME main.c -lncurses

I also have the Cygwin and Msys dlls for Ncurses copied into the directory of the compiled executable.

Update

So I figured out how to get the program to run. I deleted all the DLLs from the project folder and then added "C:\msys64\usr\bin" to my PATH environment variable. However, I would still like to know if there's a way to get this to work if I were to distribute it, since it's still relying on my installation of MSYS2.

Update 2

Gave up and just used pdcurses and it works fine.

Update 3

Nevermind, found a solution! See below.

like image 406
nesos Avatar asked Oct 26 '25 06:10

nesos


1 Answers

I figured out a solution. I'll post it here in case anyone else has this same issue. Thanks to Thomas Dickey for your help!

  1. Install the mingw-w64 toolchain and any other packages you need to compile your project (this is mostly where I messed up)
  2. Make sure to include the /mingw64/include/ncurses directory when compiling, or else gcc won't be able to find curses.h
  3. Include /mingw64/bin as a static directory or copy over the necessary dlls to the same folder as the directory

I ended up with this to compile:

gcc -I/mingw64/include/ncurses -o PROGRAMNAME main.c -lncurses -L/mingw64/bin -static
like image 50
nesos Avatar answered Oct 28 '25 22:10

nesos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!