Monday, 11 September 2017

Create .so in linux & dynamic vs static libraries

 One major advantage of static libraries being preferred even now “is speed”. There will be no dynamic querying of symbols in static libraries. Many production line software use static libraries even today.

To generate a shared library you need first to compile your C code with the -fPIC (position independent code) flag.
gcc -c -fPIC hello.c -o hello.o
This will generate an object file (.o), now you take it and create the .so file:
gcc hello.o -shared -o libhello.so
EDIT: Suggestions from the comments:
You can use

gcc -shared -o libhello.so -fPIC hello.c

http://www.geeksforgeeks.org/static-vs-dynamic-libraries/
One drawback of static libraries is, for any change(up-gradation) in the static libraries, you have to recompile the main program every time

No comments:

Post a Comment