Similar to this post: Compile multiple C source fles into a unique object file
I have to compile multiple C files into a single dynamic shared library. Here is what I have in my Makefile:
_OBJS = file1.o file2.o
CFLAGS += -Wall -I../include
SHARED_LIB =libdynamic.so
.PHONY: all
all: (SHARED_LIB)
$(SHARED_LIB):
$(CC) -fPIC -c file1.c file2.c $(CFLAGS)
$(CC) -shared -o $(SHARED_LIB) -L$/lib -ldl $(_OBJS)
However the generated shared library doesn't have the functions belonging to file2.c. How can I get it working?
Thanks.
答案 0 :(得分:0)
您没有创建目标文件(* .o)。
尝试:
$(SHARED_LIB):
$(CC) -fPIC -c file1.c -o file1.o $(CFLAGS)
$(CC) -fPIC -c file2.c -o file2.o $(CFLAGS)
$(CC) -shared -o $(SHARED_LIB) -L$/lib -ldl $(_OBJS)
此外,您在all:
目标后缺少'$'。