[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic libs example code

On Mon, 30 Aug 1999, Rob Kaper wrote:

>Does anyone have a copy of the example code to use/create shared libs that
>was posted here some time ago? I could use it at the moment!

Hmm, I don't know what article you refer to, but making shared libraries
is not difficult. Basically you need to make sure the code is compiled
with the switch '-fpic' and the library is finally linked with the switch
'-shared'. Such as:

gcc -fpic -c Part1.c
gcc -fpic -c Part2.c
gcc -shared -o MyLib.so Part1.o Part2.o -lOtherNeededLib

To use 'MyLib.so' you need to make sure the library is in a location where
the linker can find it. Do that with the '-L/path/to/MyLib.so'. When your
app that uses MyLib is compiled the runtime linker also needs to know
where to find the lib. That can be accomplished by installing MyLib.so in
a common location (such as /usr/local/lib), adding the location to
/etc/ld.so.conf, or setting the variable LD_LIBRARY_PATH to point to the
directory where MyLib.so can be found.

Hope this helps. If you wanted to know how dlopen/dlsym/dlclose etc work
then just read the manpages... :-)

 Jan 'Chakie' Ekholm |    CS at Åbo Akademi University, Turku, Finland
    Linux Inside     | I'm the blue screen of death, no-one hears you scream