2

I am not sure if I have some misunderstanding on ar -x command, here's how to repeat the problem:

Step 1. make sure there are symbols are there:

$ nm librocksdb.a | c++filt | grep -s 'rocksdb::Footer::Footer'

                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
0000000000000740 T rocksdb::Footer::Footer(unsigned long, unsigned int)
0000000000000740 T rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)

Step 2. extract members from librocksdb.a and try to find symbols:

$ ar -x librocksdb.a

$ nm *.o | c++filt | grep -s 'rocksdb::Footer::Footer'
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)
                 U rocksdb::Footer::Footer(unsigned long, unsigned int)

We can notice that all symbols are Undefined now.

Can anyone help to explain why or if I use it in a wrong way?

(background: What I am intended to do is to extract all objects from multiple static libs and re-package them into one single static library)

WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138
  • Possibly a duplicate of: https://stackoverflow.com/questions/3821916/how-to-merge-two-ar-static-libraries-into-one – selbie May 24 '19 at 07:19
  • @selbie I am not asking how to merge multiple static libraries, but the problem I met when following that method, thanks. – WoooHaaaa May 24 '19 at 07:40
  • Use the option to `nm` that lists the object file name within the library to see where the symbols are defined. Compare that with running `nm` on just the extracted object file. That should give some enlightenment. Running `ar -tv` on the Library might be illuminating too. – Jonathan Leffler May 24 '19 at 08:32
  • A probable explanation springs to mind which if correct will probably be apparent to you from the output of `ar t librocksdb.a`. If not, the question would be improved by adding that output. – Mike Kinghan May 25 '19 at 11:00
  • Could the library contain the same object file name several times, and the later version without the text symbols defined overwrote the earlier version with the text symbols defined when you extracted the files? There are ways to (ab)use `ar` to create such libraries, I think. `man ar` on macOS shows _"`-q` — (Quickly) append the specified files to the archive. If the archive does not exist a new archive file is created. Much faster than the `-r` option, when creating a large archive piece-by-piece, as no checking is done to see if the files already exist in the archive."_ (`ar -tv` again!) – Jonathan Leffler Jul 03 '19 at 21:31

0 Answers0