Mail Archives: cygwin/2002/01/06/16:17:26
Please don't send cygwin related questions to me personal. This belongs
on the cygwin list. I have copied the list and reset the Reply-To:
appropriately.
Hiroo Hayashi wrote:
> Dear Charles Wilson,
>
> I'm maintaining a perl module Term::Readline::Gnu. It is a wrapper
> module of GNU Readline Library for perl. I've received a report which
> said my module did not work with Cygwin GNU Readline Library package.
> I'd like to make my module be able to work Cygwin library and I am
> looking for information on the Internet.
>
> I've found your name from Cygwin mailling list archive.
> http://sources.redhat.com/ml/cygwin-apps/2001-01/msg00018.html
Note that near the top of my cygwin list is to release a new version of
readline that builds the DLL using NEW STYLE auto-import/export
functionality provided by recent binutils. See my message today in
cygwin mailing list archives, "Re: dll vs static importing on cygwin"
for more information.
The OLD STYLE used by the current cygwin readline releases is causing
your difficulties. You *can* work around it and build
Term::Readline::Gnu with the current cygwin readline DLL -- I did this
several months ago -- but you'd be better off just waiting until I
release the new cygwin readline build, and then try against THAT.
> It seems that you are maintaining the Cygwin GNU Readline Library
> package. If you are not proper person, could you advice me how to
> contact the maintainer or forward this message this him? Thank you.
>
>
> Let me use the following code, foo.c, to explain my problem.
> ------------------------------------------------------------------------
> #include <stdio.h>
> #include <readline/readline.h>
> char **foo = &rl_line_buffer; /* error */
>
> #if 0
> extern char *e;
> char **c = &e; /* no error */
> #else
> main(){
> char **bar;
> bar = &rl_line_buffer; /* no error */
> }
> #endif
Yep, this is a windows DLL problem. You can't use the address of an
imported variable as a static initializer, because it isn't constant.
It will depend on where the DLL is loaded into memory at each runtime.
(I'm pretty sure of that; Corrections, anyone? Robert?)
> ------------------------------------------------------------------------
>
> First I compiled this file without additional option.
>
> (HERBIE) hiroo[202] gcc -c foo.c
> foo.c:3: initializer element is not constant
>
> I'm assuming that this is due to a restriction of Windows DLL. Are
> there any way to compile this without modifying the source code?
If I am correct above, then NO, you must modify the source code.
>
> Next I found /usr/include/readline/readline_dll.h and READLINE_STATIC
> directive in it. By using this I can compile foo.c.
>
> (HERBIE) hiroo[203] gcc -c -DREADLINE_STATIC foo.c
> # no error
Now, this ought to work -- you indicate that you will link to the static
lib, so ONCE the link is perfomed, the address of rl_line_buffer will be
at a constant position within foo.exe's memory space.
> Next I tried to link this.
>
> (HERBIE) hiroo[205] gcc -DREADLINE_STATIC foo.c -lreadline -ltermcap
> Warning: resolving _rl_line_buffer by linking to __imp__rl_line_buffer (auto-import)
> nmth000000.o(.idata$4+0x0): undefined reference to `_nm__rl_line_buffer'
> collect2: ld returned 1 exit status
Ah -- you COMPILED the .c into a .o as if you were going to link
statically, and then tried to link to the import lib (dynamically).
That won't work. Add '-static' to the link command to force it to link
statically.
> It seems that ld use /usr/lib/libreadline.dll.a instead of
> /usr/lib/libreadline.a. How can I tell Cygwin ld to use static
> library instead of dynamin library?
Yep -- you need 'gcc -static'.
>
> By removing /usr/lib/readline.dll.a I have no error. And my perl
> module works well.
Right -- fallback position is if .dll.a can't be found when linking
dynamically, try to link to the .a instead.
>
> Of course I don't think removing DLL library is proper way.
No it isn't. Nit: .dll.a isn't the DLL. it is merely the import lib.
The dll is actually /usr/bin/cygreadline5.dll.
> I can give
> a full path name, /usr/lib/readline.a, to ld, but I feel this is not
> also proper way.
'gcc -static' + -DREADLINE_STATIC
Or wait for the next release of cygwin readline, which should make all
of these problems go away.
--Chuck
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -