I am new to the concept of .so
files and makefiles, so please guide me what's wrong in my makefile, when I am executing the make
command, it creates .so
files but it gives and error saying
/usr/bin/ld: subfolder/srcs/file_name.so: undefined reference to `function_name'
Before showing you the makefile, I would like to give you a glimpse of my folder structure
main_folder/
├── Makefile
├── main.c
├── main.so
├── subfolder/
│ ├── includes
│ | └─ all required .h files
│ | srcs
│ | └─ all required .c files
│ └─ ...
└── ...
Now my makefile looks like this:
APP := Test_app
APP_INSTALL_DIR ?= /home
SRCS := main.c
SRCS += $(wildcard subfolder/srcs/*.c)
INCS := $(wildcard subfolder/includes/*.h)
OBJS := $(SRCS:.c=.o)
SOS := $(OBJS:.o=.so)
CFLAGS := -I /usr/lib
LIBS += -L -lpq -ldl -Wl,-rpath
all: $(APP)
%.o: %.c $(INCS) Makefile
$(CC) -c -o $@ $(CFLAGS) $<
%.so: %.o Makefile
$(CC) -shared -o $@ $< $(LIBS)
$(APP): $(SOS) Makefile
$(CC) -o $(APP) $(SOS) $(LIBS)
install: $(APP)
cp -rv $(APP) $(APP_INSTALL_DIR)
clean:
rm -rf $(OBJS) $(APP) $(SOS)
I am not getting what I'm missing and where.