多个静态库合并

来源:互联网 发布:淘宝卖家的钱在哪里 编辑:程序博客网 时间:2024/05/21 09:21


这个方法适合下面的问题

  1. 合并多个静态库。
  2. 静态库的多级依赖。
  3. 静态库级联调用,导致链接错误。
  4. 。。。。。。

第一步:生成静态库文件
echo CREATE lib-static.a > ar.mac  回车echo SAVE >> ar.mac 回车echo END >> ar.mac 回车ar -M < ar.mac  
 
第二步:加入.o文件至静态库
ar -q lib-static.a api.o 

第三步:加入其它库
echo OPEN lib-static.a > ar.mac 回车echo ADDLIB other-static.a >> ar.mac 回车echo SAVE >> ar.mac 回车echo END >> ar.mac 回车ar -M < ar.mac 回车

如果是在makefile里面用,直接可以如下调用
define BUILD_LIBRARY  $(if $(wildcard $@),@$(RM) $@)  $(if $(wildcard ar.mac),@$(RM) ar.mac)  $(if $(filter %.a, $^),  @echo CREATE $@ > ar.mac  @echo SAVE >> ar.mac  @echo END >> ar.mac  @$(AR) -M < ar.mac  )  $(if $(filter %.o,$^),@$(AR) -q $@ $(filter %.o, $^))  $(if $(filter %.a, $^),  @echo OPEN $@ > ar.mac  $(foreach LIB, $(filter %.a, $^),  @echo ADDLIB $(LIB) >> ar.mac  )  @echo SAVE >> ar.mac  @echo END >> ar.mac  @$(AR) -M < ar.mac  @$(RM) ar.mac  )  endef  $(TargetDir)/$(TargetFileName):$(OBJS)     $(BUILD_LIBRARY) 

0 0
原创粉丝点击