1

can anyone tell how can I include already existing .a file while creating .a with this?

ar rcs libcrypt.a

I need to add libssl.a and libcrypto.a files together into a libcrypt.a file. Can you help me to solve this?

2
  • perhaps ar rcs libcrypt.a libssl.a libcrypto.a?
    – geza
    Commented Jul 8, 2017 at 13:13
  • @geza: perhaps not. While your command would run, it would put the files libssl.a and libcrypto.a into the (new) libcrypt.a archive. That much would work, but the linker would be looking for .o files and not complete .a files in the library; it wouldn't find any symbols in libcrypt.a. You have to add the object files as object files. (You can store source code and other files in archives if you wish. Very few people actually do so, but that was originally an intended use for the ar program.) Commented Jul 9, 2017 at 20:10

1 Answer 1

1

man ar tells you how to extract all the members from an archive, and it tells you how to insert members into an archive.

So extract all the members from libssl.a and libcrypto.a and insert them all into libcrypt.a, taking care to do the extracting in an empty directory.

$ mkdir scrap
$ cd scrap
$ ar -x ../libssl.a
$ ar -x ../libcrypto.a
$ ar rcs ../libcrypt.a *
$ cd ..
$ rm -r scrap/
2
  • The one-liners leave a lot of debris (extracted object files) in the current directory. The variant using the sub-directory is much cleaner, therefore. Commented Jul 9, 2017 at 20:08
  • @JonathanLeffler Quite true. Didn't consider the debris. Commented Jul 10, 2017 at 7:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.