0

Possible Duplicate:
How to merge two “ar” static libraries into one

I have multiple archive file as below

folder1/libfolder1.a
folder2/libfolder2.a
folder3/libfolder3.a

all these library have bunch of obj files.

I want to create one single archive of all these library.

ar -rcs libGlobal.a folder1/libfolder1.a folder2/libfolder2.a folder3/libfolder3.a 

but it doest work. It says I need to extract all these .a files and once I have all these obj file, I can do like below

ar -rcs `ls *.o`

but I dont want to do all this nasty stuff. I want to have clear solution something like

ar -rcs libGlobal.a `ar -x folder1/libfolder1.a` `ar -x folder2/libfolder2.a` `ar -x folder3/libfolder3.a`

the solution I want similar to this because the folder structure that I have given in this example is not that simple.

Any help would be appreciated

Community
  • 1
  • 1
  • IIRC, once the `.o` files are in the `.a` library, their relative paths no longer matter anyway, so I don't think it's particularly important to preserve them... – twalberg Sep 20 '12 at 18:37
  • thanks chepner, but that discussion also ended up with non working solution. – user1541202 Sep 20 '12 at 18:44
  • thanks twalberg, problem is that I want clear solution so include all library containt. ideally the solution ar -rcs libGlobal.a `ar -x folder1/libfolder1.a` `ar -x folder2/libfolder2.a` `ar -x folder3/libfolder3.a` should work. but for some reason it is not working – user1541202 Sep 20 '12 at 18:46
  • How is it not working? Is it failing to extract from the existing archives? Do you have file name conflicts between the archives (`foo.o` from `libfolder1.a` overwritten by `foo.o` from `libfolder2.a` since path names are not stored)? Is it failing to create a new archive? – twalberg Sep 20 '12 at 19:04

1 Answers1

0

Though it is not expressed as a single command, this should work:

pushd folder1; ar -x libfolder1.a; popd
pushd folder2; ar -x libfolder2.a; popd
pushd folder3; ar -x libfolder3.a; popd
ar -rcs libGlobal.a folder1/*.o folder2/*.o folder3/*.o
rm folder1/*.o folder2/*.o folder3/*.o
Stephane Rouberol
  • 4,286
  • 19
  • 18