Link to home
Start Free TrialLog in
Avatar of ksn76
ksn76

asked on

Can I include libraries in archives.

Hi,
Is it possible to include shared libaries in archives with "ar" command".
For example if i have file1.o and lib1.so, can I make an archive including both of them?

Thanks,
Sasi,
Avatar of bryanh
bryanh

I think the question is, is it possible _not_ to?  I do this with 'ar r file1.o lib1.so'.

If the shared library is stripped (has no symbol table), then you've got a problem.  Then you need something that reconstructs a symbol table from the dynamic symbol section in lib1.so.  I don't know of anything that does that, but it should be feasible.
ar, the standard Unix archiver, is routinely used to create Unix object libraries. The resulting file, which ends in ".a", can therefore be referred to as an archive; however, the term library is recommended as it is more descriptive for our purposes. Archive files created by ar can contain any type of file, including text and executable files; in contrast, object libraries contain only compiled object files.

The syntax for building a library from a group of object files is

ar r


for example,

ar r libmultidim.a hypercube.o mobius_strip.o klien_bottle.o tesseract.o

will create a library in the current directory called libmultidim.a, which contains the four object files given in the example.

So, if you are asking "Can I add an .SO file to an object library and expect the linker "ln" to pick up the objects at linktime/runtime the answer is NO.

If you are asking "Can I add an .SO file to an archive file?" The answer is you can add any file to an archive file.
ASKER CERTIFIED SOLUTION
Avatar of dhymes
dhymes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>So, if you are asking "Can I add an .SO file to an object library and expect the linker "ln" to pick
>up the objects at linktime/runtime the answer is NO.

Well, it works for me.

As .so files are ELF object files, just as .o files are, 'ln' can pick up the objects the same.
I pulled the above out of the linux man pages, you may know something they don't, or it is possible that some linkers can handle shared files within an archive file. The linker I am using cannot.