bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* how to build gnulib for shared libraries?
@ 2018-12-14 12:18 Szabolcs Nagy
  2018-12-20  3:18 ` Bruno Haible
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2018-12-14 12:18 UTC (permalink / raw)
  To: bug-gnulib@gnu.org; +Cc: nd

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?

only elf targets need to be supported so ideally all
gnulib replacement symbols should have hidden visibility,
object files should be built only once (with -fPIC) and
no configure checks per target binary as suggested by
https://www.gnu.org/software/gnulib/manual/html_node/Multiple-instances.html
nor libtool dependency.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to build gnulib for shared libraries?
  2018-12-14 12:18 how to build gnulib for shared libraries? Szabolcs Nagy
@ 2018-12-20  3:18 ` Bruno Haible
  2019-01-03 15:58   ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2018-12-20  3:18 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Szabolcs Nagy, nd

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to build gnulib for shared libraries?
  2018-12-20  3:18 ` Bruno Haible
@ 2019-01-03 15:58   ` Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2019-01-03 15:58 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib@gnu.org; +Cc: nd

On 20/12/2018 03:18, Bruno Haible wrote:
> 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.)

(szabolcs is my given name, i only use the hungarian order
in hungarian language context)

>> 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.

meanwhile i solved my issue in a completely different way
but it's good to know that libtool is the easy solution.

> 
> 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.

unfortunately libtool has a lot of issues which are
unlikely to be fixed any time soon.

thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-03 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 12:18 how to build gnulib for shared libraries? Szabolcs Nagy
2018-12-20  3:18 ` Bruno Haible
2019-01-03 15:58   ` Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).