gcc将多个静态库链接成一个静态库

参考:https://sourceware.org/binutils/docs/binutils/ar-scripts.html#ar-scripts

makefile如下:

 1 ARSCRIPT=script.ar
 2 SILENT=@
 3 ARCHIVES=$(wildcard $(DIR_LIB)/*.a)
 4 
 5 $(LIB_TARGET):$(OBJ)
 6     $(SILENT)echo "CREATE $@" > $(DIR_OBJ)/$(ARSCRIPT)
 7     $(SILENT)for a in $(ARCHIVES); do (echo "ADDLIB $$a" >> $(DIR_OBJ)/$(ARSCRIPT)); done
 8     $(SILENT)echo "ADDMOD $(OBJ)" >> $(DIR_OBJ)/$(ARSCRIPT)
 9     $(SILENT)echo "SAVE" >> $(DIR_OBJ)/$(ARSCRIPT)
10     $(SILENT)echo "END" >> $(DIR_OBJ)/$(ARSCRIPT)
11     $(AR) -M < $(DIR_OBJ)/$(ARSCRIPT)
12     $(RANLIB) $@

 

posted @ 2014-09-24 17:53  Jojodru  阅读(6597)  评论(0编辑  收藏  举报