Last active
June 5, 2024 14:04
-
-
Save xuhdev/1873316 to your computer and use it in GitHub Desktop.
Makefile template for shared library https://www.topbug.net/blog/2019/10/28/makefile-template-for-a-shared-library-in-c-with-explanations/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile template for a shared library in C | |
# https://www.topbug.net/blog/2019/10/28/makefile-template-for-a-shared-library-in-c-with-explanations/ | |
CC = gcc # C compiler | |
CFLAGS = -fPIC -Wall -Wextra -O2 -g # C flags | |
LDFLAGS = -shared # linking flags | |
RM = rm -f # rm command | |
TARGET_LIB = libtarget.so # target lib | |
SRCS = main.c src1.c src2.c # source files | |
OBJS = $(SRCS:.c=.o) | |
.PHONY: all | |
all: ${TARGET_LIB} | |
$(TARGET_LIB): $(OBJS) | |
$(CC) ${LDFLAGS} -o $@ $^ | |
$(SRCS:.c=.d):%.d:%.c | |
$(CC) $(CFLAGS) -MM $< >$@ | |
include $(SRCS:.c=.d) | |
.PHONY: clean | |
clean: | |
-${RM} ${TARGET_LIB} ${OBJS} $(SRCS:.c=.d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for response
but one think i am not understanding actually i install embedded eclipse for windows when i create shared library output fill generated lib.so file as for my knowladge lib.so file generate base on linux system . why its happen like that
if i successfully generated library then where i add the this line
in make
please consider the my attachment of make file