在 mingw 上使用 ncursesw6

Use ncursesw6 on mingw

我正在尝试在 windows(mingw 和 msys)上使用 ncursesw6 编译程序。

该程序已经在 linux 上使用 ncurses,在 windows 上使用 pdcurses,但今天我尝试对其进行一些更改以使用新的 ncursesw6,但没有成功。

我在 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

我在 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'

还有更多错误意味着 ncurses 没有正确链接(我认为)。

ncurses6_mingw64 目录在 $HOME/

编辑: 这是 $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

这就是 ncursesw6_config 告诉我在 msys 上 运行 它应该如何使用的内容(我认为它完全坏了):

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

$

我在/之前加了$HOME/ncursesw_mingw64/因为很明显是错的,其他的,我照着说的照抄了,因为我了解的不多

EDIT2: 我在 makefile 中对此进行了评论,但仍然出现相同的错误:

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

如果我把它改成-I/include/ncursesw -I/include,这是配置告诉我的,错误是这个:

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

出了什么问题?

已解决: 使用 mingw 提供的 ncurses 包和 运行 调整其配置文件以了解正确的 CFLAGS 和 LIBS 解决了问题。

但是: 我认为这将是一个单独的问题,但是有一个问题:我可以运行双击生成的.exe,但是msys不能运行;当我 ./win/estdis.exe 说一些关于 cygwin 的事情时,它会出现问题:Error opening terminal: cygwin.

您似乎从 ncurses homepage 下载了示例 cross-compiled 构建之一。这些配置假定典型的 MinGW 配置,/bin 中的 DLL,/include 中的 headers 和 /lib 中的 link-libraries。

可以从其他位置使用它,但您必须修改 ncursesw6-config 脚本以反映新位置。此外,DLL 必须位于 $PATH 上的某个目录中。如果不是,那可能不会干扰链接,但会阻止生成的程序 运行.

在脚本中,有一段是这样的:

prefix=""
exec_prefix="${prefix}"

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

根据目录树的图示,您可能希望将第一行更改为

prefix=/home/LNV/ncurses6_mingw64

并添加

/home/LNV/ncurses6_mingw64/bin

到您的 PATH 环境变量。

顺便说一下,MinGW 有一个 ncurses 包,您可以考虑使用它...