Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: lucia@savvy.zko.dec.com (Tim Lucia)
Subject: Re: Creating shared libraries
Date: 1995/12/18	[thread overview]
Message-ID: <4b4rsf$87n@zk2nws.zko.dec.com> (raw)
In-Reply-To: 4b43h9$23t@zk2nws.zko.dec.com


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 <stdio.h>

void main()
{
    void sharedRoutine(void);

    printf("In the main program.\n");
    sharedRoutine();
}

scratch> cat shlib.c
#include <stdio.h>

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.



  reply	other threads:[~1995-12-18  5:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-12-12  5:00 Creating shared libraries Scott Tringali
1995-12-13  5:00 ` Jochen Klein
1995-12-15  5:00 ` Tim Lucia
1995-12-18  5:00   ` Tim Lucia
1995-12-18  5:00     ` Tim Lucia [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-02-07  5:00 Creating Shared Libraries Christopher Yap
1997-02-08  5:00 ` Graham Jones
1997-02-12  5:00 ` Tim Lucia
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox