当前位置: 技术问答>linux和unix
编译时如何区分动态链接和静态链接?
来源: 互联网 发布时间:2016-03-28
本文导语: gcc的flag依靠-l(lib的名字)来链接函数库,比如要链接libm.so的时候就加上-lm做gcc的flag。但是,当编译过程中既有静态链接又有动态链接的时候,假设我加一个-lxxx,编译器是如何知道到底要链接libxxx.a还是libxxx.so呢?...
gcc的flag依靠-l(lib的名字)来链接函数库,比如要链接libm.so的时候就加上-lm做gcc的flag。但是,当编译过程中既有静态链接又有动态链接的时候,假设我加一个-lxxx,编译器是如何知道到底要链接libxxx.a还是libxxx.so呢?请高手给予指点。
|
默认优先动态库。
没有找到动态库再找静态库
没有找到动态库再找静态库
|
1 .PHONY:clean indent count
2
3 INCLUDE := $(shell pwd)/include
4 SRCS := $(shell pwd)/source
5 LIB := $(shell pwd)/lib
6 OBJ := $(shell pwd)/obj
7
8 TARGET := New_EP
9 OBJS := $(OBJ)/*.o
10 LIBS := -lpthread $(LIB)/libjpeg.a $(LIB)/add2-ioctl.o
11
12 CC := g++
13 WARN := -Wall
14 CFLAGS := -g ${WARN} -I $(INCLUDE)
15 DEBUG := -D__DEBUG__
16 LDFLAGS :=
17
18 New_EPOBJS := $(OBJ)/main.o $(OBJ)/bitmap_oper.o $(OBJ)/color_yuv2rgb.o $(OO
BJ)/common.o $(OBJ)/convertpicture.o $(OBJ)/cthread.o $(OBJ)/dh2-ioctl.o $(OO
BJ)/drv0-v4l2.o $(OBJ)/grab-ng.o $(OBJ)/identifycarnum.o $(OBJ)/jpeg_write.oo
$(OBJ)/lane.o $(OBJ)/monitorcontrol.o $(OBJ)/monitormachine.o $(OBJ)/readcoo
nf.o $(OBJ)/savepicture.o $(OBJ)/upload.o
19
20 all: ${TARGET}
21
22 New_EP: ${New_EPOBJS}
23 ${CC} ${LDFLAGS} ${DEBUG} -o $@ ${New_EPOBJS} ${LIBS}
24
25 $(OBJ)/%.o: $(SRCS)/%.cpp
26 ${CC} ${DEBUG} ${CFLAGS} -c -o $@ $
2
3 INCLUDE := $(shell pwd)/include
4 SRCS := $(shell pwd)/source
5 LIB := $(shell pwd)/lib
6 OBJ := $(shell pwd)/obj
7
8 TARGET := New_EP
9 OBJS := $(OBJ)/*.o
10 LIBS := -lpthread $(LIB)/libjpeg.a $(LIB)/add2-ioctl.o
11
12 CC := g++
13 WARN := -Wall
14 CFLAGS := -g ${WARN} -I $(INCLUDE)
15 DEBUG := -D__DEBUG__
16 LDFLAGS :=
17
18 New_EPOBJS := $(OBJ)/main.o $(OBJ)/bitmap_oper.o $(OBJ)/color_yuv2rgb.o $(OO
BJ)/common.o $(OBJ)/convertpicture.o $(OBJ)/cthread.o $(OBJ)/dh2-ioctl.o $(OO
BJ)/drv0-v4l2.o $(OBJ)/grab-ng.o $(OBJ)/identifycarnum.o $(OBJ)/jpeg_write.oo
$(OBJ)/lane.o $(OBJ)/monitorcontrol.o $(OBJ)/monitormachine.o $(OBJ)/readcoo
nf.o $(OBJ)/savepicture.o $(OBJ)/upload.o
19
20 all: ${TARGET}
21
22 New_EP: ${New_EPOBJS}
23 ${CC} ${LDFLAGS} ${DEBUG} -o $@ ${New_EPOBJS} ${LIBS}
24
25 $(OBJ)/%.o: $(SRCS)/%.cpp
26 ${CC} ${DEBUG} ${CFLAGS} -c -o $@ $