On 6/8/10 5:20 AM, Bruno Haible wrote: > Hi, > > Giuseppe Scrivano wrote: >> The problem is that readline 6.x exports `xmalloc' and `xrealloc', and >> it causes a linker error when used together with gnulib. > > According to what Chet Ramey said in > <http://lists.gnu.org/archive/html/bug-readline/2009-06/msg00003.html> > it should be possible to override 'xmalloc' and 'xrealloc' in gnulib, and > libreadline should then use the definitions from gnulib. Recall that gnulib > links statically into the program; gnulib is not compiled into a shared > library.
There are two important things to remember: linking happens beginning to end on the command line, and the linker works at file scope. The first means that if an application provides its own definition of xmalloc/xrealloc/xfree, or somehow arranges for those symbols to be defined by the time readline is linked, readline's version will not be included. The second thing is that the linker works on files: when it links a file that provides a particular function definition, all functions in that file are linked. The gnulib interface defines many more functions than the readline one: x2realloc, xcalloc, xzalloc, etc. If the application or gnulib itself uses any of those `extra' functions, the entire file from gnulib will be linked in, and you'll get a redefined symbol error. The first can be solved by putting definitions for xmalloc/xrealloc/xfree into the program's code or changing the makefile so that gnulib is linked before readline. That will probably work for the second also, but if it doesn't, I don't know if the second can be solved without taking gnulib's xmalloc.c and adding it to the list of ftp's source/object files. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/