9

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.

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).

Any ideas how we might get one of the approaches to work?

user202729
  • 3,358
  • 3
  • 25
  • 36
Broes De Cat
  • 536
  • 5
  • 14
  • I know near to nothing about windows programming and can't help you with that, but note that GNU readline is GPLed, so you can't distribute a binary only package (you can distribute pre-compiled one but binary only is copyright infraction). – AProgrammer Jan 19 '11 at 15:58
  • Ah interesting, what are exactly those requirements? (our project is open-source so we can certainly comply, but i'm not very skilled in the licences department :). Are things like distributing a binary with a reference to the online source allowed, or does the source have to be included at all times? – Broes De Cat Jan 19 '11 at 16:13
  • For that you need a lawyer. I believe binary-with-reference is allowed, as long as the original source is avaliable. The biggest hurdle is that your software must also be GPL (not any other, potentially more lenient open source license). There is a BSD-copyrighed readline clone called editline in varying stages of deadness. – Chris Lutz Mar 14 '11 at 08:27

4 Answers4

4

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:

Layout of my dev directory:

c:\dev\msys
c:\dev\mingw32
c:\dev\local32
c:\dev\mingw64
c:\dev\local64

Set some environment variables for the 32 bit build:

export CPPFLAGS=-I/c/dev/local32/include
export LDFLAGS=-L/c/dev/local32/lib

termcap 1.3.1.
Run the configure script:

./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:

/* 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

/* 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 install and it should compile without warnings or errors.

readline 6.2
Set the same CPPFLAGS and LDFLAGS variables as with termcap before calling:

./configure --prefix=/c/dev/local32 --host=i686-w64-mingw32 --enable-static --enable-shared

Edit the Makefile:

Line 40: AR = i686-w64-mingw32-ar

make install should now compile and install readline!
If you want a 64bit library, replace i686-w64-mingw32 with x86_64-w64-mingw32 and local32 with local64.

x-x
  • 7,287
  • 9
  • 51
  • 78
  • Can you give a bit more information on your actions? I tried to follow it but got stuck on two problems. Firstly termcap configure ignores the host specification and defaults to my unix targeting g++. Secondly, there is not option in the configure of readline to specify the location of the termcap library (or you also edited that)? – Broes De Cat Mar 16 '11 at 22:18
  • Great! I got it working, using mingw-w64 crosscompiling from unix, without having to change termcap files! One useful tip: you can specify CC, CXX, AR and RANLIB executables in the configure command (so you can leave the makefile unchanged) – Broes De Cat Mar 17 '11 at 10:39
  • the readline 6.2 links not working on me it show my ISP page saying it cant resolve the hostname – Blanket Fox Oct 10 '21 at 05:57
  • @Fox https://web.archive.org/web/20171009055709/http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html – x-x Oct 10 '21 at 07:06
  • ok thanks add note about it or change the link for future when someone read this – Blanket Fox Oct 10 '21 at 07:19
2

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.

Main readline functions are implemented for the native Windows console. BSD license.

Mayank
  • 8,777
  • 4
  • 35
  • 60
user704865
  • 21
  • 1
0

gnuwin32 has a port of readline: http://gnuwin32.sourceforge.net/packages/readline.htm

for non-GPL projects, libedit has a more acceptable licensing [uses BSD licensing]

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
0

There is now a cygwin distribution of readline, which worked for me. The package name is libreadline-devel

Minek Po1
  • 142
  • 1
  • 9