How do I build dynamically linked shared libraries by hand?
If you don’t want to use BSD/OS’s make header feature (see above), or if you have other issues such as a complex pre-existing makefile, then you will have to create your shared libraries `by hand’. Here are the essential steps: • All of your C and C++ source needs to be compiled with -fPIC. Often this is just a matter of inserting that string into your makefile’s CFLAGS variable. After all of the source code has been compiled, you need to link the objects into a shared object or shared library. If your shared library is libfoo.so, then your link line will look something like this: cc -shared -Wl,-soname,libfoo.so -o libfoo.so ${OBJS} ${LIBS} where ${OBJS} stands for the list of object files in your library and ${LIBS} stands for the list of shared libraries that this shared library depends on. The -shared flag tells cc that you are building a shared object or shared library; the -soname flag tells cc that you are building a shared library with the given name. • You can use ld to link t