Creating Shared Libraries from Archives

I have had a need to get access to some standard libraries, distributed as archives (*.a format) into shared libraries (*.so format). The main situation where this arrives is to build run-time plug-ins for open-architecture software which can call functions in *.so libraries dynamicly, at run time. I have needed to do this for PV-Wave and IDL, however, I hear that it also occurs for Java.

In all of my cases, I have needed to write some special wrappers to implement the interface to my software package. The software I am using cannot call the third-party libraries directly, since the arguments need some manipulation by simple wrappers. Hence, my software actually calls my custom wrappers, and its the wrappers that call the third-party libraries.

Each time I have had to do this it has taken several days to get all the kinks ironed out. So I am posting my findings here in case it is of use to future developers.

I wrote a file called wrappers.c which contains my special-purpose wrappers to the third-party library.

In each case below, all the dependencies created in wrappers.c were automagicly resolved by the ld command, and a large *.so library was created which contained all the code necessary to provide the functions I needed.

The commands I needed to create my *.so plug-in were like:

Alpha/Tru64 UN*X
     gcc -c -fpic wrappers.c
     ld -shared -o libMyPlugin.so wrappers.o -l3rdParty
Solaris
     gcc -c -fpic wrappers.c
     ld -G -o libMyPlugin.so wrappers.o -l3rdParty
Where -l3rdParty refers to the archive library, lib3rdParty.a which is searched to resolve all undefined functions called from wrappers.c
Aaron Birenboim
Last modified: Wed Nov 23 08:13:05 MST 2005