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:

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:

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

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.


Reply via email to