Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!news.maxwell.syr.edu!news.msfc.nasa.gov!sol.ctr.columbia.edu!startide.ctr.columbia.edu!wpaul From: wpaul@ctr.columbia.edu (Bill Paul) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: Help: Shared Libs Date: 30 Apr 1997 14:22:32 GMT Organization: Columbia University Center for Telecommunications Research Lines: 54 Message-ID: <5k7kj8$cv2$2@sol.ctr.columbia.edu> References: <5k5s03$f38$1@nnrp.cs.ubc.ca> NNTP-Posting-Host: startide.ctr.columbia.edu X-Newsreader: TIN [version 1.2 PL2] Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:40037 Daring to challenge the will of the almighty Leviam00se, Henry Avatar Chan (q8e192@ugrad.cs.ubc.ca) had the courage to say: : Hi, : Suppose I have a whole bunch of .o (object) files. : How do I make a .so (shared dynamic lib) out of them? If the .o files were compiled with -fpic, then you can make a shared lib out of them with ld -Bshareable (see the ld(1) man page for more details). : Do these .o files have to be compiled with -fPIC? Yes they do. No, you can't convert the objects from one format to the other. : Any full examples of creating shared libs are appreciated. You can easily do it with a simple Makefile. Say you have two source files, foo.c and bar.c, that you want to turn into a shared library called 'libtest.so.1.0'. Create a Makefile like this: ------------------snip------------------ LIB=test SHLIB_MAJOR=1 SHLIB_MINOR=0 SRCS+= foo.c bar.c .include <bsd.lib.mk> ------------------snip----------------- Then just type 'make.' You will end up with libtest.a, libtest_p.a and libtest.so.1.0. For each library, the Makefile will generate normal (.o), profiled (.po) and position independent (.so) object files and link them appropriately. The .so objects will be compiled with -fpic -DPIC. You can also type 'make libtest_pic.a' to generate a library archive of the unlinked .so objects. The standarc C library (libc) is provided in this form so that users can create a new libc.so just by replacing certain .so files and relinking, which is faster than recompiling the whole library from scratch. (It's also done on some commercial OSes where source code for the library isn't provided.) -Bill -- ============================================================================= -Bill Paul (212) 854-6020 | System Manager, Master of Unix-Fu Work: wpaul@ctr.columbia.edu | Center for Telecommunications Research Home: wpaul@skynet.ctr.columbia.edu | Columbia University, New York City ============================================================================= "Now, that's "Open" as used in the sentence "Open your wallet", right?" =============================================================================