After 2.5.8, we can enable automatic merging of all dependent static libraries by setting the build.merge_archive strategy, for example:
The mul static library automatically merges the add and sub static libraries to generate a complete libmul.a library containing add/sub code.
This merge is relatively stable and complete, supports ar and msvc/lib.exe, also supports the merge of static libraries generated by the cross-compilation tool chain, and also supports static libraries with the same name obj file.
If the automatic merge does not meet the requirements, we can also actively call the utils.archive.merge_archive module to merge the specified static library list in the after_link stage.
target("test")
after_link(function (target)
import("utils.archive.merge_staticlib")
merge_staticlib(target, "libout.a", {"libfoo.a", "libbar.a"})
end)
In fact, our previous version already supports merging static libraries through add_files("*.a").
target("test")
set_kind("binary")
add_files("*.a")
add_files("*.c")
Related issues: #1638