#7559 closed Bugs (fixed)
gcc-compatible symbol visibility not supported for clang
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | config |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: | jonathan.jones@… |
Description
boost/config/compiler/gcc.hpp defines BOOST_SYMBOL_VISIBLE and BOOST_SYMBOL_EXPORT to be attribute((visibility("default"))) when not running under Windows. But boost/config/compiler/clang.hpp does not define these symbols. This creates compatibility problems on OS X when linking binaries built with gcc to binaries built with clang. Since clang is used as a replacement for gcc, I would expect that BOOST_SYMBOL_VISIBLE and BOOST_SYMBOL_EXPORT should be defined in the same way for clang.
Change History (10)
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
follow-up: 5 comment:4 by , 10 years ago
comment:5 by , 10 years ago
Is there a reason for not also defining BOOST_SYMBOL_EXPORT?
I'll add BOOST_SYMBOL_EXPORT
and BOOST_SYMBOL_IMPORT
after collecting information about clang on the Windows platform. It will be done in a few days, I think.
comment:6 by , 10 years ago
on the Windows platform clang uses the code path in platform/win32.hpp.
clang supports both __attribute__
and __declspec
.
What I'd recommend is to put in compiler/clang.hpp the following
#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)) #define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default"))) #define BOOST_SYMBOL_IMPORT #define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default"))) #endif
comment:7 by , 10 years ago
Just a note to say I'm aware of this issue, but as I'm not a Clang user I'd really like for someone to provide a patch that I can just blindly go ahead and apply...
Thanks, John Maddock.
comment:8 by , 10 years ago
I was planning to add the following
// // Dynamic shared object (DSO) and dynamic-link library (DLL) support // #if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && !defined(__CYGWIN__) // All Win32 development environments, including 64-bit Windows and MinGW, define // _WIN32 or one of its variant spellings. Note that Cygwin is a POSIX environment, // so does not define _WIN32 or its variants. # define BOOST_HAS_DECLSPEC #else # define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default"))) # define BOOST_SYMBOL_IMPORT #endif #define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
But I'd like to defer the support for the Windows platform,
since there are some subtleties on that platform.
I'm going to add BOOST_SYMBOL_EXPORT
and BOOST_SYMBOL_IMPORT
macros
only on other platforms (i.e. the #else
branch) for the meantime.
The #if
condition in the above code is copied from config/compiler/gcc.hpp
.
John, do you know why !defined(__CYGWIN__)
is needed?
It looks verbose, since _WIN32
or its variants are not defined on cygwin.
Also, would it be nice to define BOOST_SYMBOL_IMPORT
only on non-Windows platform
, as mentioned by Mathias?
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:10 by , 10 years ago
I chose to use Mathias' code
#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32) # define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default"))) # define BOOST_SYMBOL_IMPORT # define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default"))) #endif
rather than copying the code from config/compiler/gcc.hpp
.
Oops, the underscores in __attribute__ were taken as WikiFormatting.