From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,1510452cd1ec58ee X-Google-Attributes: gidfee84,public From: lucia@savvy.zko.dec.com (Tim Lucia) Subject: Re: Creating shared libraries Date: 1995/12/18 Message-ID: <4b4rsf$87n@zk2nws.zko.dec.com>#1/1 X-Deja-AN: 122211138 distribution: world references: <4ak145$7t4@news.res.ray.com> <4as3tn$rab@zk2nws.zko.dec.com> <4b43h9$23t@zk2nws.zko.dec.com> organization: Digital Equipment Corporation reply-to: lucia@zko.dec.com newsgroups: comp.unix.osf.osf1 ARGH! Truncated again. In article <4ak145$7t4@news.res.ray.com>, tringali@news.ed.ray.com (Scott Tringali) writes: |>How do I create my own shared libraries? I am working with a large (30+) |>number of applications that have many common libraries. These are created with |>cc -c, then ar, and then linked into the final application with cc. |> |>Is there any way I can take these libraries, compile them to a .so, and save on |>disk space and memory? I haven't found any references how to do this in the cc |>or ld man pages. |> You didn't look hard enough. It is in the ld(1) manual page: NAME ld, uld - link editor and ucode link editor SYNOPSIS ld [ option ... ] file ... uld [ option ... ] file ... DESCRIPTION The ld command invokes the DEC OSF/1 link editor which links extended coff object files. The archive format understood by ld is the one created by the archiver ar(1). -shared Produce a shared object. This includes creating all of the tables for run-time linking and resolving references to other specified shared objects. The object created may be used by the linker to make dynamic executables. -call_shared Produce a dynamic executable. The object created may use shared objects at run-time. Here is a simple example. Note that LD_LIBRARY_PATH must be set to include the directory with the shared library, or, the library must live in /usr/shlib. scratch> cat Makefile all: sharedapp sharedapp: main.o shlib.so cc -call_shared -o sharedapp main.o shlib.so main.o: main.c cc -g -c main.c shlib.so: shlib.o ld -shared shlib.o -o shlib.so /usr/shlib/libc.so shlib.o: shlib.c cc -g -c shlib.c clean: rm -f sharedapp main.o shlib.so scratch> cat main.c #include void main() { void sharedRoutine(void); printf("In the main program.\n"); sharedRoutine(); } scratch> cat shlib.c #include void sharedRoutine(void) { printf("In the shared routine in the shared library.\n"); } scratch> make clean all rm -f sharedapp main.o shlib.so cc -g -c main.c ld -shared shlib.o -o shlib.so /usr/shlib/libc.so cc -call_shared -o sharedapp main.o shlib.so scratch> (export LD_LIBRARY_PATH=.; ./sharedapp) In the main program. In the shared routine in the shared library. scratch> (export LD_LIBRARY_PATH=.; ladebug ./sharedapp) Welcome to the Ladebug Debugger Version 4.0-10 ------------------ object file name: ./sharedapp Reading symbolic information ...done (ladebug) listobj listobj ObjectName Start Addr Size Symbols (bytes) Loaded ---------------------------------------------------------------------------- /sharedapp 0x120000000 8192 Yes /shlib.so 0x3ffbfff0000 8192 Yes /usr/shlib/libc.so 0x3ff80800000 901120 Yes (ladebug) quit quit scratch> Good luck, Tim -- Timothy J. Lucia Email: mailto:lucia@zko.dec.com Digital Equipment Corporation Phone: 603.881.2615 110 Spitbrook Road ZKO2-3/K06 Fax: 603.881.0120 Nashua, NH USA 03062-2698 I'd rather be cycling.