Windows下静态链接,正确工作的readline库?

Bro*_*Cat 8 c++ windows cygwin mingw libreadline

我们正在开发一个依赖于GNU readline库的C++软件包,我们通常使用gcc构建(至少要求版本4).现在我们想将它移植到Windows,获得一个静态链接的版本,我们可以重新分发,而无需用户编译.

我尝试了几种方法:

  • 使用Cygwin构建(不使用提供的readline和-mno-cygwinMinGW编译器),
  • 使用MinGW和GnuWin32的readline构建(未解析的依赖关系到stat64,我无法解析),
  • 使用MinGW构建并从源代码构建readline和必需的pdcurses(最有希望的方法,得到一个静态二进制文件!但是获得的交互式shell表现不正确,例如退格架没有可视化).

我们如何获得其中一种工作方法的想法?

x-x*_*x-x 4

经过类似的挫折后,我刚刚使用MinGW-w64编译了 libreadline 6.2 的 32 位和 64 位版本。这是我的做法:

我的开发目录的布局:

c:\dev\msys
c:\dev\mingw32
c:\dev\local32
c:\dev\mingw64
c:\dev\local64
Run Code Online (Sandbox Code Playgroud)

为 32 位构建设置一些环境变量:

export CPPFLAGS=-I/c/dev/local32/include
export LDFLAGS=-L/c/dev/local32/lib
Run Code Online (Sandbox Code Playgroud)

术语 1.3.1。
运行配置脚本:

./configure --host=i686-w64_mingw32 --prefix=/c/dev/local32
Run Code Online (Sandbox Code Playgroud)

编辑 termcap.c 并修复顶部的几行。我的看起来像这样:

/* Emacs config.h may rename various library functions such as malloc.  */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef emacs

#include <lisp.h>       /* xmalloc is here */
/* Get the O_* definitions for open et al.  */
#include <sys/file.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
//#ifdef HAVE_UNISTD_H
#include <unistd.h>
//#endif

#else /* not emacs */

//#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)
//#else
//char *getenv ();
//char *malloc ();
//char *realloc ();
//#endif
Run Code Online (Sandbox Code Playgroud)

和 tparam.c

/* Emacs config.h may rename various library functions such as malloc.  */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef emacs
#include "lisp.h"       /* for xmalloc */
#else

//#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
//#else
//char *malloc ();
//char *realloc ();
//#endif

/* Do this after the include, in case string.h prototypes bcopy.  */
//#if (defined(HAVE_STRING_H) || defined(STDC_HEADERS)) && !defined(bcopy)
#define bcopy(s, d, n) memcpy ((d), (s), (n))
//#endif

#endif /* not emacs */
Run Code Online (Sandbox Code Playgroud)

修改Makefile:

Line 23: CC = i686-w64-mingw32-gcc
Line 24: AR = i686-w64-mingw32-ar
Line 36: prefix = /c/dev/local32
Line 49: #oldincludedir = /usr/local
Run Code Online (Sandbox Code Playgroud)

调用make install后,它应该可以编译,没有警告或错误。

readline 6.2
在调用之前设置与 termcap 相同的 CPPFLAGS 和 LDFLAGS 变量:

./configure --prefix=/c/dev/local32 --host=i686-w64-mingw32 --enable-static --enable-shared
Run Code Online (Sandbox Code Playgroud)

编辑生成文件:

Line 40: AR = i686-w64-mingw32-ar
Run Code Online (Sandbox Code Playgroud)

make install现在应该编译并安装 readline!
如果您想要 64 位库,请将i686-w64-mingw32替换为x86_64-w64-mingw32,并将local32替换为local64