Add support for prelinked static libraries
For some projects it makes sense to ship static libraries to customers. They, however come with a few downsides compared to dynamic libraries (there may be other ones too).
- Compiling with LTO /
INTERPROCEDURAL_OPTIMIZATION
makes an archive file which can have LLVM bitcode (or similar on other compilers?) rather then purely machine code, users may not get the benefits of LTO unless they use a compatible compiler. - All symbols are public to the static library user, which might lead to duplicate symbols and can encourage our users to use our internal symbols!
😄 , similar use case toC_VISIBILITY_PRESET
/CXX_VISIBILITY_PRESET
=hidden
.
Some compiler/linker combinations support a command to link multiple .o
files to a single .o
file, when started through the compiler driver this supports performing LTO too. So the workflow would be SOURCE -> OBJECTS -> SINGLE PRELINK OBJECT -> ARCHIVE. Commands are something like the following:
clang++ ${FLAGS} -r -o TARGET-prelink.o OBJECTS
ar cr TARGET.a TARGET-prelink.o
ranlib TARGET.a
- Meson discussion (including a CMake user who is implementing this with CMake scripts): https://github.com/mesonbuild/meson/pull/5499
- Meson PR (supports gcc only I think): https://github.com/mesonbuild/meson/pull/7983
- SO referencing Xcode build-in support for this (
Perform Single-Object Prelink
): https://stackoverflow.com/questions/14259405/pre-link-static-libraries-for-ios-project - This appears to be known as 'partial linking' in some places
Edited by Harry Mallon