同时使用动态库和静态库时怎么写makefile

项目经验。 

关键语句:

    $(CC)  -L $(LIB_FOR_SRS) -o $(OUTPUT_DIR)/$(TARGET)  $(OBJS) -Wl,-Bstatic -lssl -lcrypto  \
    -Wl,-Bdynamic $(DYNAMIC_LINK_OPTION) $(STATIC_LINK_OPTION) 

也可以换成(链接):

    $(LD)  -L $(LIB_FOR_SRS) -o $(OUTPUT_DIR)/$(TARGET)  $(OBJS) -Wl,-Bstatic -lssl -lcrypto  \
    -Wl,-Bdynamic $(DYNAMIC_LINK_OPTION) $(STATIC_LINK_OPTION) 

LIB_FOR_JSON          = ./lib/json_lib/*
LIB_FOR_MQTT          = ./lib/mqtt_lib/*
LIB_FOR_SQLITE3       = ./lib/sqlite3_lib/*
LIB_FOR_SRS           = ./lib/srslibrtmp_lib/srs_librtmp.a
SRC_DIR               = ./src
OUTPUT_DIR            = ./output
SYS_LOCAL_LIB_DIR     = /usr/local/lib

TARGET    = ecSmartFire
RM        = rm -rf 
MV        = mv 
CP        = cp -r
LDCONFIG  = ldconfig

#### compile comment #####	
COMPILE                    = aarch64-linux-gnu-
CC                         = $(COMPILE)gcc
STRIP                      = $(COMPILE)strip
LD                         = $(COMPILE)ld

COMPILE_OPTION             = -O2 -Wall  -Wcomment -Wformat -Wmissing-braces -Wswitch -Wuninitialized \
                             -Wbad-function-cast -Waggregate-return -Wmultichar -Wsign-compare -Wshadow
#COMPILE_OPTION_DEBUG       = -gdwarf-2 -g 
COMPILE_ALL_OPTION         += $(COMPILE_OPTION) $(COMPILE_OPTION_DEBUG)

STATIC_LINK_OPTION         =  -lsqlite3  -lm  -lpthread -lc  -lstdc++  -ldl
DYNAMIC_LINK_OPTION        = -lpaho-mqtt3a -ljson-c

LINK_DIFF_OPTION           = -Wl,

OBJS_MAIN                  = main.o
OBJS_EC_UART_232           = ec_uart_232.o
OBJS_EC_UART_485           = ec_uart_485.o
OBJS_EC_MANAGE_PLCE        = ec_manage_plce.o
OBJS_EC_SOCKET_VIDEO       = ec_socket_video.o
OBJS_EC_MQTT_ANDROID       = ec_mqtt_android.o
OBJS_EC_SQLITE             = ec_sqlite.o
OBJS_EC_STORE_INFO         = ec_store_info.o
OBJS_EC_MANAGE_CAMERA      = ec_manage_camera.o
OBJS_DEAL_REQUEST_LOOP     = deal_request_loop.o
OBJS_PUSH_VIDEO            = push_video.o

OBJS    = $(OBJS_MAIN) $(OBJS_EC_UART_232) $(OBJS_EC_UART_485) $(OBJS_EC_MANAGE_PLCE) $(OBJS_EC_SOCKET_VIDEO) \
		$(OBJS_EC_MQTT_ANDROID) $(OBJS_EC_SQLITE) $(OBJS_EC_STORE_INFO) $(OBJS_EC_MANAGE_CAMERA) $(OBJS_DEAL_REQUEST_LOOP) \
		$(OBJS_PUSH_VIDEO)
							 
$(TARGET):$(OBJS)
	$(CC)  -L $(LIB_FOR_SRS) -o $(OUTPUT_DIR)/$(TARGET)  $(OBJS) -Wl,-Bstatic -lssl -lcrypto  \
	-Wl,-Bdynamic $(DYNAMIC_LINK_OPTION) $(STATIC_LINK_OPTION) 
	$(STRIP) $(OUTPUT_DIR)/$(TARGET)

$(OBJS_MAIN):
	$(CC) -c $(SRC_DIR)/main.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_UART_232):
	$(CC) -c $(SRC_DIR)/ec_uart_232.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_UART_485):
	$(CC) -c $(SRC_DIR)/ec_uart_485.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MANAGE_PLCE):
	$(CC) -c $(SRC_DIR)/ec_manage_plce.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_SOCKET_VIDEO):
	$(CC) -c $(SRC_DIR)/ec_socket_video.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MQTT_ANDROID):
	$(CC) -c $(SRC_DIR)/ec_mqtt_android.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_SQLITE):
	$(CC) -c $(SRC_DIR)/ec_sqlite.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_STORE_INFO):
	$(CC) -c $(SRC_DIR)/ec_store_info.c $(COMPILE_ALL_OPTION)
$(OBJS_EC_MANAGE_CAMERA):
	$(CC) -c $(SRC_DIR)/ec_manage_camera.c $(COMPILE_ALL_OPTION)
$(OBJS_DEAL_REQUEST_LOOP):
	$(CC) -c $(SRC_DIR)/deal_request_loop.c $(COMPILE_ALL_OPTION)
$(OBJS_PUSH_VIDEO):
	$(CC) -c $(SRC_DIR)/push_video.c  $(COMPILE_ALL_OPTION)

.PHONY:clean copylib
clean:
	-$(RM) $(OUTPUT_DIR)/* $(OBJS)
copylib:
	$(CP) $(LIB_FOR_MQTT) $(SYS_LOCAL_LIB_DIR)/
	$(CP) $(LIB_FOR_JSON) $(SYS_LOCAL_LIB_DIR)/
	$(CP) $(LIB_FOR_SQLITE3) $(SYS_LOCAL_LIB_DIR)/
	$(LDCONFIG)
	

 

已标记关键词 清除标记
相关推荐