I am trying to compile a static library. I followed the steps which were given in an answer to this question but it is not working. Following is my makefile.
PROJECT = lq.a
OBJECTS = dlmalloc.o queue.o.o
CFLAGS = -o -Wall -pedantic
all: $(PROJECT)
.c.o:
gcc -c $(CFLAGS) $<
$(PROJECT): $(OBJECTS)
libtool -o $(PROJECT) -static $(OBJECTS)
And I get the following error.
libtool: unrecognized option `-o'
What is the correct way of writing this makefile?
You can use the program ar
to create static libraries using the following syntax:
ar rcs my_library.a file1.o file2.o
So, in your case:
$(PROJECT): $(OBJECTS)
ar rcs $(PROJECT) $(OBJECTS)
You can find an explanation of the options on the man page, but basically:
r
says insert the given object files in to the archive (replacing any older versions of the same thing)c
says create the archive if it isn't already there (normally this happens anyway, but this option suppresses the warning).s
says to write an object-file index into the archive.