bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to build gnulib for shared libraries?


From: Bruno Haible
Subject: Re: how to build gnulib for shared libraries?
Date: Thu, 20 Dec 2018 04:18:52 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-139-generic; KDE/5.18.0; x86_64; ; )

Hi Szabolcs,

(or should I say "Hi Nagy"? Sorry, with Hungarian proper names, I never
know what is the surname and what is the given name.)

> by default gnulib is not built with -fPIC so it is not
> suitable for shared libraries.
> 
> is there an easy way to build gnulib .a with -fPIC so
> it can be used with shared libraries and executables as
> well within the same project?

The easy way is to use libtool, in combination with the technique
described in
https://www.gnu.org/software/gnulib/manual/html_node/Modified-build-rules.html .

You find an example here:
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-tools/gnulib-lib/Makefile.am

For shared libraries that are private to your application, this is all
you need.

For shared libraries that are visible to other applications, you should
consider hiding the gnulib symbols. Since the set of gnulib symbols depends
on the platform, I usually follow the approach to export only a given set
of symbols (defined by .h files) and hide all the rest. Find an
example of this technique here:
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=blob;f=gettext-tools/libgettextpo/Makefile.am

> only elf targets need to be supported so ideally all
> gnulib replacement symbols should have hidden visibility

If all your targets support __attribute__((__visibility__("hidden"))),
you can use the option determined by gnulib module 'lib-symbol-visibility'.
Documentation:
https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html

Otherwise the only reliable way to hide symbols is by adding #define
instructions through config.h.

> object files should be built only once (with -fPIC)

Try 'configure --disable-static --enable-shared'.

> nor libtool dependency.

libtool is part of the GNU build system. If you don't want libtool,
you're on your own. You'll have different build rules for every platform,
essentially. It can be done (look at libncurses, for example), though.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]