In <[EMAIL PROTECTED]>, mal content <[EMAIL PROTECTED]> typed: > Hi. > > So, if I want to link to the shared library /usr/local/libxyz.so, I > simply add '-lxyz' > to my program link commands. But what if I want to link to the equivalent > static library? > > The GCC manual says: > > -static > On systems that support dynamic linking, this prevents linking > with the shared libraries. On other systems, this option has no > effect. > > This is unsuitable as it will obviously compile in EVERYTHING statically, > including the system libc. > > How come there's no (obvious) portable way to link to static libraries? The > '-l' method is "portable" because the Makefile doesn't need to know the > suffix > used for shared libraries on any particular platform (so on FreeBSD, dylib on > Darwin, sl on HP-UX, dll on Windows, and most likely more). However, to link > against static libs, the only option appears to be to do: > > cc -o myprog myprog.o /usr/local/libxyz.a > > The static library must be specified by full path, using the '.a' > suffix - obviously > contains potential portability problems in the event of a platform not using > the '.a' suffix (although I've not actually seen any to date) - > because otherwise > the existence of libxyz.so will cause a program that uses '-l' to link against > the dynamic library instead of the static. > > Is there a better way?
I'd try using ld with the "-r -static" flags to do a partial link with just the stuff you want statically linked, then a second ld (or maybe cc?) step to create the executable with everything else linked in shared. I haven't tried it, so I don't know that it will work. You may need to add extra flags to get ld to not include things in the static link as well. Check the ld man page for lots more info. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"