Subject: Re: Shared Libs and executables: How?
To: None <hacksaw@user1.channel1.com>
From: Mike Long <mike.long@analog.com>
List: netbsd-help
Date: 10/28/1996 11:04:37
>Date: Sun, 27 Oct 1996 14:46:52 -0500
>From: Hacksaw <hacksaw@gerbils.fe.com>

[fvdl writes:]
>>For a.out shared libs, bsd.lib.mk does the following:
>>
>>	1) compile the source files with -fpic
>>	2) bundle them in an archive called libXXX_pic.a
>>	3) ld -x -Bshareable -Bforcearchive -o libXXX.so.X.Y libXXX_pic.a
>
>O.K., that produces the libs, but how about the executables to refer
>to them?
>
>I have seen a -Bdynamic options for ld, the -shared option for gcc.

Usually gcc is used to link dynamic binaries:

gcc -o mybin mybin.o -L.../mylib -lmylib

If .../mylib/libmylib.so.*.* exists, you should end up with a
dynamically linked binary.  Alternatively, you can refer to the
library directly instead of using -L and -l:

gcc -o mybin mybin.o .../mylib/libmylib.so.*

The drawback of this second method is that you can never change the
location of libmylib.so.*; if you do, the binary will stop working
because ld.so can't find libmylib.

>These things tend to either complain, or do the wrong thing when I use
>them. (The wrong thing being compiling in static libraries).

What are the complaints?

You may need to run ldconfig before ld will recognize and use your
new shared library.  It shouldn't be necessary, but it may help.  See
ldconfig(1).

In my /etc/rc.local I add /usr/X11R6/lib and /usr/local/lib to the
paths given to ldconfig, so ld can find X11 and other local shared
libraries:

/sbin/ldconfig -m /usr/X11R6/lib /usr/local/lib

-- 
Mike Long <mike.long@analog.com>     <URL:http://www.shore.net/~mikel>
VLSI Design Engineer         finger mikel@shore.net for PGP public key
Analog Devices, CPD Division          CCBF225E7D3F7ECB2C8F7ABB15D9BE7B
Norwood, MA 02062 USA       (eq (opinion 'ADI) (opinion 'mike)) -> nil