Search code examples
cncursesmingw-w64

Use ncursesw6 on mingw


I am trying to compile a program using ncursesw6 on windows (mingw and msys).

The program already works with ncurses on linux, and with pdcurses on windows, but today I tried to change it a little to use the new ncursesw6, but it didn't work.

I tried this in the makefile:

# -*- MakeFile -*-

# MACRO = substitute with this

# export

export  OS = linux
export  TST = false
export  DBG = false

 ifeq ($(OS), linux)
export  CC = gcc
export  CFLAGS = -std=c11 -O3 -march=native
export  LIBS = -l ncurses -l pthread -l m

 else
  ifeq ($(OS), win)
CFLAGS_NCURSESW = -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506L -I$(HOME)/ncurses6_mingw64/include/ncursesw -I$(HOME)/ncurses6_mingw64/include
LIBS_NCURSESW = -L$(HOME)/ncurses6_mingw64/lib -Wl,--enable-auto-import -lncursesw -lpsapi
export  CC = gcc.exe
export  CFLAGS = -std=c11 -O3 $(CFLAGS_NCURSESW)
export  LIBS = -lm $(LIBS_NCURSESW)
  endif
 endif

I got these errors at the linking stage of the make:

make[1]: Entering directory `/home/LNV/EstDis-2.b.2/win'
gcc.exe -std=c11 -O3 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506L -I /home/LNV/ncurses6_mingw64/include/ncursesw -I /home/LNV/ncurses6_mingw64/include ..//obj//main.o ..//libalx//obj//alx_file.o ..//libalx//obj//alx_getnum.o ..//libalx//obj//alx_math.o ..//libalx//obj//alx_ncur.o ..//modules//about//obj//about.o ..//modules//calc//obj//calc.o ..//modules//ctrl//obj//start.o ..//modules//tui//obj//dist.o ..//modules//tui//obj//menus.o -o estdis.exe -lm -L /home/LNV/ncurses6_mingw64/lib -Wl,--enable-auto-import -lncursesw -lpsapi
..//libalx//obj//alx_ncur.o:alx_ncur.c:(.text+0x4): undefined reference to `initscr'
..//libalx//obj//alx_ncur.o:alx_ncur.c:(.text+0x9): undefined reference to `nonl'
..//libalx//obj//alx_ncur.o:alx_ncur.c:(.text+0xe): undefined reference to `cbreak'

and more errors meaning that ncurses is not correctly linked (I think).

ncurses6_mingw64 directory is at $HOME/

EDIT: This is a tree of $HOME:

/home/LNV$ tree
.
├── EstDis-2.b.2
│   ├── bin
│   │   ├── estdis
│   │   └── Makefile
│   ├── inc/
│   ├── libalx/
│   ├── LICENSE.txt
│   ├── Makefile
│   ├── modules/
│   ├── obj/
│   ├── README.txt
│   ├── src/
│   ├── tst/
│   └── win
│       └── Makefile
└── ncurses6_mingw64
    ├── bin
    │   ├── libformw6.dll
    │   ├── libmenuw6.dll
    │   ├── libncursesw6.dll
    │   ├── libpanelw6.dll
    │   └── ncursesw6-config
    ├── include
    │   └── ncursesw
    │       ├── curses.h
    │       ├── eti.h
    │       ├── form.h
    │       ├── menu.h
    │       ├── nc_mingw.h
    │       ├── nc_tparm.h
    │       ├── ncurses_dll.h
    │       ├── ncurses.h
    │       ├── ncurses_mingw.h
    │       ├── panel.h
    │       ├── termcap.h
    │       ├── term_entry.h
    │       ├── term.h
    │       ├── tic.h
    │       └── unctrl.h
    └── lib
        ├── libformw.a
        ├── libformw.dll.a
        ├── libmenuw.a
        ├── libmenuw.dll.a
        ├── libncursesw.a
        ├── libncursesw.dll.a
        ├── libpanelw.a
        └── libpanelw.dll.a

And this is what ncursesw6_config tells about how it should be used when I run it on msys (I think it is completely broken):

LNV@DESKTOP ~
$ ./ncurses6_mingw64/bin/ncursesw6-config
Usage: ncursesw6-config [options]

Options:
    --prefix    echos the package-prefix of ncursesw
    --exec-prefix   echos the executable-prefix of ncursesw

    --cflags    echos the C compiler flags needed to compile with ncursesw
    --libs      echos the libraries needed to link with ncursesw

    --version   echos the release+patchdate version of ncursesw
    --abi-version   echos the ABI version of ncursesw
    --mouse-version echos the mouse-interface version of ncursesw

    --bindir    echos the directory containing ncursesw programs
    --datadir   echos the directory containing ncursesw data
    --includedir    echos the directory containing ncursesw header files
    --libdir    echos the directory containing ncursesw libraries
    --mandir    echos the directory containing ncursesw manpages
    --terminfo  echos the $TERMINFO terminfo database path
    --terminfo-dirs echos the $TERMINFO_DIRS directory list
    --termpath  echos the $TERMPATH termcap list

    --help      prints this message

LNV@DESKTOP ~
$ ./ncurses6_mingw64/bin/ncursesw6-config  --cflags
-D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506L -I/include/ncursesw -I/include

LNV@DESKTOP ~
$ ./ncurses6_mingw64/bin/ncursesw6-config  --libs
-L/lib -Wl,--enable-auto-import -lncursesw -lpsapi

$

I added $HOME/ncursesw_mingw64/ before / because it was obvious that it was wrong, but the rest, I copied it exactly as it says because I don't know much about it.

EDIT2: I commented this in the makefile, and still gives me the same error:

# -I$(HOME)/ncurses6_mingw64/include/ncursesw -I$(HOME)/ncurses6_mingw64/include

If I change it to -I/include/ncursesw -I/include, which is what the config tells me, the error is this one:

..//src//alx_file.c:30:21: fatal error: curses.h: No such file or directory

What is going wrong?

SOLVED: Using the ncurses package provided with mingw and running its config file to know the correct CFLAGS and LIBS solved the problem.

HOWEVER: I think this will be a separate question, but there is a problem: I can run the .exe generated by double clicking on it, but msys can't run it; it gives a problem when i do ./win/estdis.exe saying something about cygwin: Error opening terminal: cygwin.


Solution

  • That looks as if you downloaded one of the sample cross-compiled builds from the ncurses homepage. Those are configured assuming a typical MinGW configuration, with the DLLs in /bin, the headers under /include and the link-libraries in /lib.

    It is possible to use that from another location, but you would have to modify the ncursesw6-config script to reflect the new location. Also, the DLLs have to be in some directory on your $PATH. If they are not, that may not interfere with linking, but will prevent the resulting programs from running.

    In the script, there is a section like this:

    prefix=""
    exec_prefix="${prefix}"
    
    bindir="${exec_prefix}/bin"
    includedir="${prefix}/include"
    libdir="${exec_prefix}/lib"
    datarootdir="${prefix}/share"
    datadir="${datarootdir}"
    mandir="${datarootdir}/man"
    

    Based on the illustration of your directory tree, you would want to change that first line to

    prefix=/home/LNV/ncurses6_mingw64
    

    and add

    /home/LNV/ncurses6_mingw64/bin
    

    to your PATH environment variable.

    By the way, MinGW has a package for ncurses, which you might consider using...

    screenshot of MinGW installer