I am making a simple lib to use in my apps to save me the trouble of defining some functions over and over…
Here’s my makefile:
CC=gcc CFLAGS=-Wall -g -Wextra OBJS=getline.o debug.o LIB=libjimi.a .PHONY: clean purge libjimi.so : $(OBJS) ar rcs $(LIB) $(OBJS) @echo done! %.o : %.c $(CC) $(CFLAGS) -c $^ clean : @rm *.o purge : clean @rm $(LIB)
Now I get a segfault if I link the library, but if I link the object files that I link to create the library, it works…advice?
Your target say libjimi.so which is the extension for a shared library, it should just be libjimi.a for a static lib.
And note that when you use a static lib you just link it in like any other object file, but with a shared lib you use the -l syntax.