José Abell's research blog

NTS (Note-To-Self): Creating dynamically linked libraries

A nice extensive tutorial can be found here.

In a nutshell:

gcc -Wall -fPIC -c \*.c  
gcc -shared -Wl,-soname, -o \*.o  
mv /opt/lib  
ln -sf /opt/lib/ /opt/lib/  
ln -sf /opt/lib/ /opt/lib/
  • -Wall: include warnings. See man page for warnings specified.
  • -fPIC: Compiler directive to output position independent code, a characteristic required by shared libraries. Also see “-fpic”.
  • -shared: Produce a shared object which can then be linked with other objects to form an executable.
  • -Wl,options: Pass options to linker.
  • In this example the options to be passed on to the linker are: -soname The name after the -o option is passed to gcc.
  • Option -o: Output of operation. In this case the name of the shared object to be output will be

See note on “Library Paths”