Statically link bundled libraries

Dan Nicholson nicholson at endlessm.com
Wed Jun 22 18:17:56 UTC 2016


On Wed, Jun 22, 2016 at 10:54 AM, Sébastien Wilmet <swilmet at gnome.org> wrote:
> Hi,
>
> Is there an example somewhere of a flatpak which statically links its
> bundled libraries?
>
> Because I don't think there is any reasons to have dynamic linking for
> something bundled.
>
> With Autotools, I know that the libraries must be configured with
> --enable-static, but on the application side I don't know what to do
> (yes I could search in the docs, but if there is already an example...).

It's not at all straightforward to do static linking, but here's how
I'd try to do assuming autotools for everything.

Configure libraries with --enable-static --disable-shared. Then you'll
only get the static libraries installed and the linker can't even try
to do dynamic linking. In order to pull in everything needed, you'd
then want to use the pkg-config --static option so that it returns the
entire list of libraries in Requires.private and Libs.private. You
should probably be able to accomplish this by setting the environment
variable PKG_CONFIG="pkg-config --static". That assumes that the
environment variable is respected everywhere, but the pkg-config
autoconf macros do that.

That's not full static linking (you'd need to tell the compiler/linker
you want that), but I think it would accomplish the case you're
thinking about where you only want the bundled libraries to be
statically linked and don't need to provide a truly static binary.

Good luck!



More information about the xdg-app mailing list