linux - [Solved-3 Solutions] How to merge two “ar” static libraries into one ? - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to merge two “ar” static libraries into one ?
Linux - Solution 1:
You can extract the object from both the .a files and create your .a file using the extracted .os:
Linux - Solution 2:
- There are at least three ways to do this natively.
- The first and most portable way is to use libtool.
- After having built the other libraries also with libtool, you can combine them just by adding the .la libs to an automake libaz_la_LIBADD variable, or directly from a Makefile with something like:
The other two are at least available when using GNU ar. You can use an MRI script (named for example libaz.mri), such as:
and then execute ar as:
You can use a thin archive (option -T), which will allow adding other archives without getting them nested inside, although the downside is that if you want to distribute the static library, the detached object will be missing:
All the above methods gracefully handle overlapping member names from the original archives.
Otherwise, you'd have to unpack into different directories and repack again, to avoid replacing overlapping member names:
Linux - Solution 3:
You can try this:
You will lost some object files if there are members with same name in both a.a and b.a so, you need to extract members of different archives into different folder:
Additionally, it is posible that there are multiple members of same name in one archive (say in a.a), if you run ar x a.a, you will get only one for those members of same name.
The only way to extract all members of same name in one archive is to specify the member number by option 'N':
One optional solutions is that you can combine multiple archives into one shared library: