文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>linux下链接静态链接库

linux下链接静态链接库

时间:2011-04-25  来源:hoy

生成静态链接库/动态链接库的makefile如下:

#CC:=arm-linux-gcc
CFLAGS :
= -I..
LDFLAGS :
= -lpthread -lrt

SRCS :
= $(wildcard *.c)

ifdef ARCH
libclient :
= libclient-$(ARCH).a
else
libclient :
= libclient.a
endif

all: $(libclient) libclient.so

$(libclient): client.o net.o
$(AR)
-rcv $@ $^

libclient.so: client.o net.o
$(CC)
-shared -o $@ $^

.depend: Makefile $(SRCS)
@$(CC) $(CFLAGS)
-MM $(SRCS) >$@
sinclude .depend

clean:
rm
-rf *.o .depend $(test_client) apitest $(libclient) libclient.so

链接动态链接库的makefile如下:

ARCH=arm-linux

ifdef ARCH
CC:
=$(ARCH)-gcc
AR:
=$(ARCH)-ar
export ARCH
export CC
export AR
endif

CFLAGS:
=-I..
LDFLAGS:
=-L. -lrt

SRCS :
= $(wildcard *.c)

ifdef ARCH
camera_track :
= camera_track-$(ARCH)
LIB:
=-lclient-$(ARCH)
else
camera_track :
= camera_track
LIB:
=-lclient
endif

all: $(camera_track)

$(camera_track): camera_track.o camera_ctrl.o
$(CC) $(LDFLAGS)
-o $@ $^ $(LIB)

.depend: Makefile $(SRCS)
@$(CC) $(CFLAGS)
-MM $(SRCS) >$@
sinclude .depend

clean:
rm
-rf *.o .depend $(camera_track)


当需要直接用命令行进行编译时,可以用如下命令:
arm-linux-gcc -L. -lrt -o camera_track camera_track.c camera_ctrl.c -lclient

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载