当前位置:网站首页>Share a general compilation method of so dynamic library

Share a general compilation method of so dynamic library

2022-07-07 01:23:00 wandersky0822

CC      :=$(CROSS_COMPILE)gcc
LD      :=$(CROSS_COMPILE)ld
CFLAGS  := -fPIC -Wall
LDFLAGS :=  -shared -Wl,-soname=libdrdev.so.2
SOURCE  := $(wildcard *.c)
OBJS    := $(patsubst %.c,%.o,$(SOURCE))
TARGET_LIB := libdrdev.so.2.1.0
  
all:$(OBJS)
        @echo $(OBJS)
        # $(LD) $(LDFLAGS) -o $(TARGET_LIB) $(OBJS) 
        $(CC) $(LDFLAGS) -o $(TARGET_LIB) $(OBJS)
  
%.o:%.c
        @echo Compiling $< ...
        $(CC) -c $(CFLAGS)  $< -o $*.o

.PHONY:clean
clean:
        rm $(TARGET_LIB) *.o -rf

Several knowledge points , Explain the following :

-fPIC    Position is irrelevant

-shared  seeing the name of a thing one thinks of its function , Generating shared libraries

$(wildcard *.c)    List all under the folder .c file  
 $(patsubst %.c,%.o,$(SOURCE))  stay $(SOURCE) Search for .c file , Replace with .o

%.o:%.c  % wildcard , You can guess almost

$< All dependence

$*  All goals % The previous part .

原网站

版权声明
本文为[wandersky0822]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061732150535.html