Windows 下静态链接、正常工作的 readline 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4737082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Statically linked, correctly working readline library under Windows?
提问by Broes De Cat
We're developing a C++ software package which depends on the GNU readline library and we usually build using gcc (requiring at least version 4). Now we would like to port this to Windows, obtaining a statically linked version which we can redistribute without requiring compilation by users.
我们正在开发一个依赖于 GNU readline 库的 C++ 软件包,我们通常使用 gcc 构建(至少需要版本 4)。现在我们想把它移植到 Windows,获得一个静态链接的版本,我们可以在不需要用户编译的情况下重新分发它。
I've tried several approaches:
我尝试了几种方法:
- Building using Cygwin (no go with the provided readline combined with
-mno-cygwin
or a MinGW compiler), - Building using MinGW and readline from GnuWin32 (unresolved dependencies to stat64, which I could not resolve),
- Building using MinGW and building readline and required pdcurses from source (most promising approach, got to a static binary! But the obtained interactive shell behaved incorrectly, e.g. backspace was not visualized).
- 使用 Cygwin 构建(不使用提供的 readline
-mno-cygwin
或 MinGW 编译器), - 使用 MinGW 和来自 GnuWin32 的 readline 构建(对 stat64 的未解决依赖项,我无法解决),
- 使用 MinGW 构建并构建 readline 并需要来自源代码的 pdcurses(最有希望的方法,得到了静态二进制文件!但获得的交互式 shell 行为不正确,例如退格键未可视化)。
Any ideas how we might get one of the approaches to work?
任何想法我们如何才能使其中一种方法起作用?
采纳答案by x-x
After similar frustrations, I have just now compiled both a 32bit and 64bit version of libreadline 6.2 using MinGW-w64. Here's my how I did it:
在经历了类似的挫折之后,我刚刚使用MinGW-w64编译了 32 位和 64 位版本的 libreadline 6.2 。这是我的做法:
Layout of my devdirectory:
我的dev目录的布局:
c:\dev\msys
c:\dev\mingw32
c:\dev\local32
c:\dev\mingw64
c:\dev\local64
Set some environment variables for the 32 bit build:
为 32 位构建设置一些环境变量:
export CPPFLAGS=-I/c/dev/local32/include
export LDFLAGS=-L/c/dev/local32/lib
termcap 1.3.1.
Run the configure script:
期限上限 1.3.1。
运行配置脚本:
./configure --host=i686-w64_mingw32 --prefix=/c/dev/local32
Edit termcap.c and fix up a few lines at the top. Mine looks like this:
编辑 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
and tparam.c
和 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 */
Modify the 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
After that call make installand it should compile without warnings or errors.
在那之后调用make install并且它应该编译没有警告或错误。
readline 6.2
Set the same CPPFLAGS and LDFLAGS variables as with termcap before calling:
readline 6.2
在调用之前设置与 termcap 相同的 CPPFLAGS 和 LDFLAGS 变量:
./configure --prefix=/c/dev/local32 --host=i686-w64-mingw32 --enable-static --enable-shared
Edit the Makefile:
编辑生成文件:
Line 40: AR = i686-w64-mingw32-ar
make installshould now compile and install readline!
If you want a 64bit library, replace i686-w64-mingw32with *x86_64-w64-mingw32* and local32with local64.
make install现在应该编译并安装 readline!
如果您需要 64 位库,请将i686-w64-mingw32替换为 *x86_64-w64-mingw32* 并将local32 替换为local64。
回答by user704865
Check out MinGWEditLine library
An EditLine API implementation for the native Windows Console. This BSD-licensed library provides command line editing and history functions similar to those found in GNU Readline.
本机 Windows 控制台的 EditLine API 实现。这个 BSD 许可的库提供类似于 GNU Readline 中的命令行编辑和历史记录功能。
Main readline functions are implemented for the native Windows console. BSD license.
主要的 readline 函数是为本地 Windows 控制台实现的。BSD 许可证。
回答by Foo Bah
gnuwin32 has a port of readline: http://gnuwin32.sourceforge.net/packages/readline.htm
gnuwin32 有一个 readline 端口:http: //gnuwin32.sourceforge.net/packages/readline.htm
for non-GPL projects, libedit has a more acceptable licensing [uses BSD licensing]
对于非 GPL 项目,libedit 具有更可接受的许可 [使用 BSD 许可]