Boost logo

Boost :

Subject: [boost] [config] Request for BOOST_SYMBOL_IMPORT_VISIBLE ?
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2011-01-28 19:37:10


Hi,

I propose the introduction of BOOST_SYMBOL_IMPORT_VISIBLE to Boost.Config
that behaves like BOOST_SYMBOL_IMPORT in all cases except gcc (and like
compilers?) where it expands to "__attribute__((visibility("default")))".
I believe this is need to address the following two scenarios:

(For gcc, assume all libraries are built with the following option:
-fvisibility=hidden)

**********
Scenario 1
**********
Export class MyException from Library A.
Catch MyException in Library B, and be able to throw or rethrow it from
Library B.
Catch MyException in Library C.

To be able to do this with gcc, MyException has to be visible from Library
B since the exception handler in Library C will look for the class
definition of MyException in Library B [1]. I don't believe it's possible
to do this "out of the box" with Boost.Config and still support gcc and
msvc libs. Conventionally, one would do the following:

//---------------
//Start Library A
//---------------
#ifdef MYLIB_BUILD
#define MYLIB_API BOOST_SYMBOL_EXPORT
#else
#define MYLIB_API_BOOST_SYMBOL_IMPORT
#endif

class MYLIB_API MyException ... { ... };
//-------------
//End Library A
//-------------

But this technique fails to make MyException visible from Library B with
gcc. And where I to use BOOST_SYMBOL_VISIBLE instead, it would fail to
export MyException from Library A with msvc.

**********
Scenario 2
**********
Export class MyShape from Library A.
Import class MyShape from Library A into Library B and have Library B
export the following the function: MyShape & foo();
Import MyShape and foo into Library C, and Library C export the function:
MyShape & bar();

To be able to do this with gcc, MyShape has to be visible from Library B
and Library C [2]. Conventionally, one would do the following:

//---------------
//Start Library A
//---------------
#ifdef LIB_A_BUILD
#define LIB_A_API BOOST_SYMBOL_EXPORT
#else
#define LIB_A_API_BOOST_SYMBOL_IMPORT
#endif

class LIB_A_API MyShape ... { ... };

//---------------
//Start Library B
//---------------
#ifdef LIB_B_BUILD
#define LIB_B_API BOOST_SYMBOL_EXPORT
#else
#define LIB_B_API_BOOST_SYMBOL_IMPORT
#endif

LIB_B_API MyShape & foo();

//---------------
//Start Library C
//---------------
#ifdef LIB_C_BUILD
#define LIB_C_API BOOST_SYMBOL_EXPORT
#else
#define LIB_C_API_BOOST_SYMBOL_IMPORT
#endif

LIB_C_API MyShape & bar();

But this leads back to the same problem/proposed solution as Scenario 1.

Thanks in advance,

Mostafa

[1] http://gcc.gnu.org/wiki/Visibility: "Problems with C++ exceptions
(please read!)", 2nd Paragraph.
[2] http://gcc.gnu.org/wiki/Visibility: "Problems with C++ exceptions
(please read!)", 3rd Paragraph.


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