$ gcc -c -fPIC test1.cThen you combine the object files into a shared library, like this:
$ gcc -shared -fPIC -o libtest.so test1.o test2.o
$ gcc -o app app.o -L. -ltest
$ gcc -static -o app app.o -L. -ltest
$ gcc -o app app.o -L. -ltest -Wl,-rpath,/usr/local/libThen, when app is run, the system will search /usr/local/lib for any required shared libraries.