Your makefile recipe for libfigure.so does not include the target name for the link phase, so gcc places the output in a.out, even for the shared library. You also need to use the
-fPIC
compile option during the compilation phase of the library objects, not the link phase. Also, there should not be a space after
-Wl,
and you need to specify
-rpath=.
So your makefile becomes
CC = gcc
program: main.o libfigure.so
$(CC) main.o -Wl,-rpath=. -L. -lfigure -o program
main.o: main.c
$(CC) main.c -c -o main.o
calc.o calc.c
$(CC) calc.o -fPIC -c -o calc.o
libfigure.so: calc.o
$(CC) -shared calc.o -o libfigure.so
If you are doing things with shared libraries, or even static libraries, you should probably take a look at
Libtool[
^] which can help with all the intricacies of building libraries.