hackorama
hackorama
Sample Code - Using shared libs on UNIX


Sample C code for :

1. Creating a shared library
2. Runtime loading of a shared library
3. Calling a method from the loaded library


On GNU/Linux :

share.c
cc -fPIC -c share.c -o share.o
ld -shared share.o -o share.sl
main.c [ using dlopen(), dlsym() ]
cc main.c -o main -ldl


On HP-UX :

share.c
cc +z -c share.c -o share.o
ld -b share.o -o share.sl
main.c [ using shl_load(), shl_findsym() ]
cc main.c -o main


The linux sample code should work for other UNIX flavours, which use dlopen()/dlsym(). Only HP-UX uses shl_load()/shl_findsym(). Please look at the man pages of cc and ld for the correct flags to be used for the particular version of UNIX.


Saturday, 01-Dec-2001 21:54:20 PST kishan at hackorama dot com