I tried to build a static library by merging two others with "link_whole" but the Ninja build file use only the output and no the inputs.
It seems that gcc-ar is not able to directly merge multiples static libraries into one.
On IRC, @nirbheek suggested to patch meson to use the libraries object files in this case.
What would be the best way to solve this problem ?
Afaik, you can't do that easily with autotools either, you have to unpack both .a files, then repack all of the .o files into a new .a file. It would be nice if meson could do that.
Note that on OSX/iOS, you need to the Apple's libtool (which is not the same as GNU libtool) to achieve this.
What is the actual problem you are trying to solve by doing the merge? E.g. why is it not sufficient to just link both libraries to the final target?
My usecase involves merging about 10 libraries to make life easier for iOS devs so they don't have to worry about linking order and so they have everything they needed.
My usecase involves merging about 10 libraries to make life easier for iOS devs so they don't have to worry about linking order and so they have everything they needed.
You can already do this, with:
static_library('foo',
objects : [bar1.extract_all_objects(), bar2.extract_all_objects(), ...])
If it doesn't work, that's a bug.
Just an update: the extract_all_objects() thing only works for static libraries built by Meson, so we still need to implement link_whole: for linking multiple static libraries into one static library.
I'm also running into this. I want to build a static library that also contains the object files of all its dependencies, including external dependencies (meson.get_compiler('c').find_library(...)).
I'm also looking for combining a meson-generated libfoo.a with an external dependency libbar.a into a "complete" static library, libcombined.a. It seems that extract_all_objects dosen't work on the output of find_library; is there a workaround to use link_whole now to achieve this?
This is also problematic when using both_libraries, since you can't just say:
library(
...
link_with : my_static_helper,
)
That only works when library is a shared lib, given that it makes meon's library() function basically useless.