Re: [xml] Generating a correct xml2-config for use with --libs

Stefan Kost wrote:

Hi Gary,

but libxml2 does networking (see nanoftp and the likes).


I know, which is why libxml2 links with the appropriate libraries (-lsocket etc). However, that doesn't mean that any application which links with libxml2 must also link with the networking libraries.

For instance, if I have foo.c:

#include <libxml/parser.h>
   xmlDocPtr doc = NULL;
   doc = xmlNewDoc(BAD_CAST "1.0");
   (void) printf("hello world\n");
   <do things which are completely unrelated to networking>
   return (0);

And I compile it as:

cc -o foo foo.c -I/usr/local/libxml/include/libxml2 -R/usr/local/libxml/sparc/lib -L/usr/local/libxml/sparc/lib -lxml2

That will work. It's the job of the linker to work out the libxml2 uses networking libraries and needs to also link -lsocket (etc) at runtime.

If I use ldd to determine the dependencies of the application it shows:

bash-2.03$ ldd foo =>     /usr/local/libxml/sparc/lib/ =>     /usr/lib/ =>     /usr/local/lib/ =>     /usr/lib/ =>     /usr/lib/ =>     /usr/lib/ =>     /usr/lib/ =>     /usr/lib/

i.e. the application is only dependant on lxml2, but the linker has worked out (correctly) that libxml2 in turn depends on a number of libraries (e.g. libz, libsocket, etc..)

As I said in my earlier mail, I find it hard to believe that you have to specify a libraries dependant libraries when you link an application with the library in order for it to work. What happens if you miss a library out because you don't know about it?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]