我们正在开发一个依赖于 GNU readline 库的 C++ 软件包,我们通常使用 gcc 构建(至少需要版本 4)。现在我们想将其移植到 Windows,获得一个静态链接版本,我们可以重新分发该版本而无需用户编译。
我尝试了几种方法:
- 使用 Cygwin 构建(不要使用提供的 readline 结合
-mno-cygwin
或 MinGW 编译器), - 使用 MinGW 和 GnuWin32 的 readline 构建( Unresolved 对 stat64 的依赖性,我无法解决),
- 使用 MinGW 构建并从源构建 readline 和所需的 pdcurses(最有希望的方法,得到一个静态二进制文件!但获得的交互式 shell 行为不正确,例如退格键未可视化)。
有什么想法可以让其中一种方法发挥作用吗?
最佳答案
在经历了类似的挫折之后,我刚刚使用 MinGW-w64 编译了 libreadline 6.2 的 32 位和 64 位版本。 .这是我的做法:
我的 dev 目录布局:
c:\dev\msys
c:\dev\mingw32
c:\dev\local32
c:\dev\mingw64
c:\dev\local64
为 32 位build设置一些环境变量:
export CPPFLAGS=-I/c/dev/local32/include
export LDFLAGS=-L/c/dev/local32/lib
termcap 1.3.1. 强>
运行配置脚本:
./configure --host=i686-w64_mingw32 --prefix=/c/dev/local32
编辑 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
和 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 */
修改生成文件:
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
之后调用 make install 并且它应该可以编译而不会出现警告或错误。
readline 6.2 强>
在调用之前设置与 termcap 相同的 CPPFLAGS 和 LDFLAGS 变量:
./configure --prefix=/c/dev/local32 --host=i686-w64-mingw32 --enable-static --enable-shared
编辑生成文件:
Line 40: AR = i686-w64-mingw32-ar
make install 现在应该编译并安装 readline!
如果您想要 64 位库,请将 i686-w64-mingw32 替换为 x86_64-w64-mingw32 并将 local32 替换为 local64.
关于c++ - 静态链接,在 Windows 下正确工作的 readline 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4737082/