How to make a shared library from a static library under ubuntu using gcc

I have a static library libsrp.a, I want to make a general library libsrp.so from it that contains all the characters. please tell me how to do .so under ubuntu.

thank

+3
source share
2 answers

Compile the object files contained in libsrp.a with a 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 in a shared library, as in

gcc -shared -o libshared.so foo.o bar.o
+3
source

Use the flag --whole-archive:

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

From the ld man page (my emphasis):

- -      , -whole-archive, , . , . .

+2

Source: https://habr.com/ru/post/1741220/


All Articles