Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve to merge static library #1638

Closed
waruqi opened this issue Sep 4, 2021 · 2 comments
Closed

Improve to merge static library #1638

waruqi opened this issue Sep 4, 2021 · 2 comments

Comments

@waruqi
Copy link
Member

waruqi commented Sep 4, 2021

old solution

target("test")
    set_kind("static")
    add_files("src/*.a")

It does not support merging archive libraries containing .o files with the same name. And it is very inconvenient to merge dependent target libraries.

new solution

we use set_policy("build.merge_archive", true) to enable merge archive intead of linking for all dependent targets.

target("add")
    set_kind("static")
    add_files("src/add.c")

target("sub")
    set_kind("static")
    add_files("src/sub.c")

target("mul")
    set_kind("static")
    add_deps("add", "sub")
    add_files("src/mul.c")
    set_policy("build.merge_archive", true)

we can also call module script to merge static library.

target("test")
    after_link(function (target)
        import("utils.archive.merge_staticlib")
        merge_staticlib(target, "libout.a", {"libfoo.a", "libbar.a"})
    end)
@waruqi waruqi added this to the v2.5.8 milestone Sep 4, 2021
@SirLynix
Copy link
Member

SirLynix commented Sep 4, 2021

What advantages are there to merge static libraries? Is it supported by all toolchains?

@waruqi
Copy link
Member Author

waruqi commented Sep 4, 2021

What advantages are there to merge static libraries? Is it supported by all toolchains?

Some users only want to distribute a single static library externally, they don't want to provide too many static libraries.

Currently supports ar and msvc/lib.exe, and should be able to support most toolchains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants