How to merge 2 .a libraries to one .a library on Linux?

Posted on In QA

We have 2 static .a libraries and we would like to merge them into a single one for easier usage.

How to merge 2 .a libraries to one .a library on Linux?

With GNU ar, you can specify the single command-line option -M and control it with a script supplied via standard input, like the MRI “librarian” program, beside of controlling ar’s activity using command-line options.

You can use this command to merge 2 .a libraries, say ezm.a and libformat.a, to a single .a library, say libezm.a:

ar -M <build-lib.mri

The build-lib.mri is as follows.

create libezm.a
addlib ezm.a
addlib cppformat/build/libformat.a
save
end

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *