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

Stefan

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>
<blah>
int
main(void)
{
   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
   libxml2.so.2 =>     /usr/local/libxml/sparc/lib/libxml2.so.2
   libc.so.1 =>     /usr/lib/libc.so.1
   libz.so =>     /usr/local/lib/libz.so
   libm.so.1 =>     /usr/lib/libm.so.1
   libsocket.so.1 =>     /usr/lib/libsocket.so.1
   libnsl.so.1 =>     /usr/lib/libnsl.so.1
   libdl.so.1 =>     /usr/lib/libdl.so.1
   libmp.so.2 =>     /usr/lib/libmp.so.2
   /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1

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?

Gary





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