????Linux ??????archive?????????????
?????漰????ar
????ar ??飺?????????????????????????
?????漰???
????t – ?????????????
????r[ab][f][u] – ???????????????????????
????[s] – ???????????
????ar -M [<mri-script] – ??? ar ???????
??????????????????? man ?????
???????????
?????????????? ? 7????????????

???????????????
?????? ? 7?п???????CdtLog.a ????? CdtLog.o ?????????? ?? ?? xml.a ???? TXmlParser.o ?? xmlparser.o ???????????
??????? CdtLog.o ??????????????? ? 8???????????μ????? demo.a???????????demo.a ???????? CdtLog.o ??? xml.a??
???????????????????? CdtLog.o??TXmlParser.o ?? xmlparser.o?????????????? Windows ?????????????

??????????????????? 1
?????????? demo.a ?????????????????????????? TXmlParser.o ?? xmlparser.o ????????????????????????????????
??????????????????????????????? 8 ??????? Linux ??????????????
??????????????????
?????????о?????а????????????????????????′?????μ??????????
???????????????????????μ??????????ar ?????
???????????? 1 ?????鷳???????漰???????????????????????????????????????????м??????
???????????? ?嵥 2 createlib.sh????? ar ?????????д?????
?????嵥 2 createlib.sh
????rm demo.a
????rm ar.mac
????echo CREATE demo.a > ar.mac
????echo SAVE >> ar.mac
????echo END >> ar.mac
????ar -M < ar.mac
????ar -q demo.a CdtLog.o
????echo OPEN demo.a > ar.mac
????echo ADDLIB xml.a >> ar.mac
????echo SAVE >> ar.mac
????echo END >> ar.mac
????ar -M < ar.mac
????rm ar.mac
??????????? Linux makefile ????? ar ?????????о???????????????д?? ?嵥 3 BUILD_LIBRARY????????
?????嵥 3 BUILD_LIBRARY
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 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)
??????? ? 9???????????????????????????? demo.a ?????????????????

??????????????????????
????Linux ?????????????????????????
???????? GCC ???????????????
????It makes a difference where in the command you write this option; the linker
????searches and processes libraries and object files in the order they are specified.
????Thus?? ‘ foo.o -lz bar.o ’ searches library ‘ z ’ after file ‘ foo.o ’ but before
????‘ bar.o ’ . If ‘ bar.o ’ refers to functions in ‘ z ’ ?? those functions may not be loaded.
?????????????????????????????????????Щ??????? :
????$(CXX) $(LINKFLAGS) $(OBJS) -Xlinker “-(” $(LIBS) -Xlinker “-)” -o $@
?????????????????????????????? -Xlinker “-(” ?? -Xlinker “-)” ????????? g++ ????????У? ?????????????о????????????????????????????
?????漰???????-Xlinker
????-Xlinker option
????Pass option as an option to the linker. You can use this to supply system-specific
????linker options which GCC does not know how to recognize.
????С??
????????????? Linux ?????????????????????????????????????? Linux ???????????????÷?????????????? ???????????? Linux ??ó?????д Linux Makefile ??????????????????