Boost logo

Boost :

Subject: Re: [boost] [config] GCC symbol visibility across shared libraries
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-05-20 10:21:27


Alexander Arhipenko
> On Thu, May 6, 2010 at 7:42 PM, Jürgen Hunold wrote:
> >
> > The patch replaces
> > __declspec(dllexport) with BOOST_SYMBOL_EXPORT
> > __declspec(dllimport) with BOOST_SYMBOL_IMPORT
> > and removes visibility declarations from forward
> > declarations
>
> The first version of BOOST_SYMBOL_EXPORT/IMPORT macro
> had slightly different definition for gcc (something like this):
> #define BOOST_SYMBOL_EXPORT __attribute__((visibility("default"))
> #define BOOST_SYMBOL_IMPORT
>
> Assume that I've built boost filesystem library with hidden
> visibility.
> After that I've used boost filesystem functionality in my custom
> shared library foo (also build with hidden visibility).
> Assume also that boost filesystem was used as an
> implementation detail.
> You will never find any references to filesystem in foo's
> public interface.

Each dynamic library should define its own import/export macro to adorn the symbols of that library that should be exported/visible. Those macros should be based upon BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT and whether the dynamic library is being built or used:

#ifdef BUILDING_MYLIB
# define MYLIB_EXPORT BOOST_SYMBOL_EXPORT
#else
# define MYLIB_EXPORT BOOST_SYMBOL_IMPORT
#endif

Using MYLIB_EXPORT for all public symbols in MyLib, and defining BUILDING_MYLIB only when compiling MyLib, will do what you want.

Arguably, "EXPORT" in "MYLIB_EXPORT" is misleading, at least for MyLib's clients. Perhaps "MYLIB_VISIBLE" is a better name, leaving BOOST_SYMBOL_VISIBLE, or whatever it may be called, for the non-import/export cases.

> 2)
> What do you think about having BOOST_SYMBOL_EXPORT/IMPORT
> always defined?

If that's not what's being done -- I haven't looked at the patch itself -- then I agree. Those macros should always be defined and each library must decide which to use as shown above.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk