views:

341

answers:

2

hi , i have a static library libsrp.a, i want to make a shared library libsrp.so from it that contains all symbols . please tell me how to make a .so under ubuntu.

thanks

A: 

Recompile the object files contained in libsrp.a with the flag to create position independent code (fpic) as in

gcc -fpic -c foo.c
gcc -fpic -c bar.c

Now you can combine foo.o and bar.o into a shared library as in

gcc -shared -o libshared.so foo.o bar.o
Jasmeet
A: 

Use the --whole-archive flag:

gcc -shared -o libsrp.so -Wl,--whole-archive -lsrp -Wl,--no-whole-archive

From the ld man page (my emphasis):

--whole-archive For each archive mentioned on the command line after the --whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library. This option may be used more than once.

R Samuel Klatchko
If the original .a file contains object files which are compiled without fPIC, can the newly generated corresponding .so file work properly?
solotim
@solotim - I've been successfully able to use non PIC code in shared objects on 32 bit Linux - although it looks like that may not be the case for 64 bit Linux.
R Samuel Klatchko