I would like to compile .c files to a .so (shared library).
And I don’t understand why, I have that makefile that makes me an error:
LIB = libmy.so
SRC = lib.c
CC = gcc
OBJ = $(CC) -c -fPIC $(SRC)
all: $(LIB)
re: fclean all
$(LIB): $(OBJ)
$(CC) -shared -fPIC $(OBJ) -o $(LIB)
clean:
$(RM) $(OBJ)
fclean: clean
$(RM) $(LIB)
Thanks in advance for helping.
The problem is in the following line:
When expanded this becomes:
Hence the error.
What you probably wanted was :
To save you having to manually convert all
.csource files to.oyou can use a rule like this instead ofOBJ = lib.o:This creates a variable
OBJcontaining a list of all the files inSRCwith any.cextension changed to.o. eg. If we hadSRC = foo.c bar.cthen the rule above would automatically expand to: