I am trying to understand static and shared Libraries.
I want to do the following to create a makefile that does separate compilation and linking such that a static library is created and linked in forming the final static executable.
I have the following code for the Makefile, but I am getting the following error
Makefile:13: *** missing separator. Stop.
But I am also trying to understand how to actually link/create libraries.
If I run the commands after line 12 in the terminal they work, but not in the makefile.
myProgram: main.o addSorted.o freeLinks.o
gcc -lm -o myProgram main.o addSorted.o freeLinks.o
main.o: main.c
gcc -O -c -lm main.c main.h
addSorted.o: addSorted.c addSorted.h
gcc -O -c -lm addSorted.c
freeLinks.o: freeLinks.c freeLinks.h
gcc -O -c -lm freeLinks.c
ar rc libmylib.a main.o addSorted.o freeLinks.o //Error Line
ranlib libmylib.a
gcc -o foo -L. -lmylib foo.o
clean:
rm -f myProgram main.o addSorted.o freeLinks.o
Also, if you can assist in improving the code, I would really appreciate it.
ar,ranlibandgcclines are supposed to be the recipe for what target? - Etan ReisnermyProgram. That's why I need assistance. Also the line where I am getting error, does not containtab- user3337714mylib.a, left justified), followed by two lines that begin with a "tab" (ar rc libmylib.a main.o addSorted.o freeLinks.o, thenranlib libmylib.a). The two lines must be consecutive (no intervening blank lines). Here is a good tutorial: A Simple Makefile Tutorial - paulsm4