mirror of
https://github.com/boostorg/config.git
synced 2025-07-31 12:57:16 +02:00
Major upgrade to Boost.Config symbol visibility macros for shared libraries, based on patches from Jürgen Hunold with mods by Beman Dawes. Upgrade Boost.System to use the new visibility macros. Fixes #3697 and provides foundation for fixing 2114, 2309, etc.
[SVN r62140]
This commit is contained in:
@ -317,6 +317,7 @@ void g() { return f(); }
|
|||||||
|
|
||||||
[#config_features]
|
[#config_features]
|
||||||
|
|
||||||
|
|
||||||
[section Macros that describe optional features]
|
[section Macros that describe optional features]
|
||||||
|
|
||||||
The following macros describe features that are not required by the C++
|
The following macros describe features that are not required by the C++
|
||||||
@ -332,10 +333,6 @@ The platform supports BeOS style threads.
|
|||||||
[[`BOOST_HAS_CLOCK_GETTIME`][Platform][
|
[[`BOOST_HAS_CLOCK_GETTIME`][Platform][
|
||||||
The platform has the POSIX API `clock_gettime`.
|
The platform has the POSIX API `clock_gettime`.
|
||||||
]]
|
]]
|
||||||
[[`BOOST_HAS_DECLSPEC`][Compiler][
|
|
||||||
The compiler uses `__declspec(dllexport)` and `__declspec(dllimport)` to
|
|
||||||
export/import symbols from dll's.
|
|
||||||
]]
|
|
||||||
[[`BOOST_HAS_DIRENT_H`][Platform][
|
[[`BOOST_HAS_DIRENT_H`][Platform][
|
||||||
The platform has the POSIX header `<dirent.h>`.
|
The platform has the POSIX header `<dirent.h>`.
|
||||||
]]
|
]]
|
||||||
@ -868,9 +865,98 @@ the configuration.
|
|||||||
[section Macros for libraries with separate source code]
|
[section Macros for libraries with separate source code]
|
||||||
|
|
||||||
The following macros and helper headers are of use to authors whose libraries
|
The following macros and helper headers are of use to authors whose libraries
|
||||||
include separate source code, and are intended to address two issues: fixing
|
include separate source code, and are intended to address several issues:
|
||||||
the ABI of the compiled library, and selecting which compiled library to link
|
|
||||||
against based upon the compilers settings.
|
* Controlling shared library symbol visibility
|
||||||
|
* Fixing the ABI of the compiled library
|
||||||
|
* Selecting which compiled library to link against based upon the compilers settings
|
||||||
|
|
||||||
|
See [@http://svn.boost.org/trac/boost/wiki/Guidelines/Separate Guidelines for Authors of Boost Libraries Containing Separate Source]
|
||||||
|
|
||||||
|
[section Macros controlling shared library symbol visibility]
|
||||||
|
|
||||||
|
Some compilers support C++ extensions that control which symbols
|
||||||
|
will be exported from shared libraries such as dynamic shared objects (DSO's) on Unix-like
|
||||||
|
systems or dynamic-link libraries (DLL's) on Windows.
|
||||||
|
|
||||||
|
The Microsoft VC++ compiler has long supplied
|
||||||
|
`__declspec(dllexport)` and `__declspec(dllimport)` extensions for this purpose,
|
||||||
|
as do virtually all other compilers targeting the Windows platform.
|
||||||
|
|
||||||
|
Modern versions of the GNU GCC compiler provide the `__attribute__((visibility("default")))`
|
||||||
|
extension to indicate that a symbol should be exported. All other symbols may be hidden by using the
|
||||||
|
`-fvisibility-hidden` or `-fvisibility-ms-compat` compiler switches.
|
||||||
|
|
||||||
|
Boost supplies several macros to make it easier to manage symbol visibility in a way that
|
||||||
|
is portable between compilers and operating systems.
|
||||||
|
|
||||||
|
[table
|
||||||
|
[[Macro ][Description ]]
|
||||||
|
[[`BOOST_SYMBOL_EXPORT`][
|
||||||
|
Defines the syntax of a C++ language extension that indicates a symbol is to be exported from a shared library.
|
||||||
|
If the compiler has no such extension, the macro is defined with no replacement text.
|
||||||
|
]]
|
||||||
|
[[`BOOST_SYMBOL_IMPORT`][
|
||||||
|
Defines the syntax of a C++ language extension that indicates a symbol is to be imported from a shared library.
|
||||||
|
If the compiler has no such extension, the macro is defined with no replacement text.
|
||||||
|
]]
|
||||||
|
[[`BOOST_SYMBOL_VISIBLE`][
|
||||||
|
Defines the syntax of a C++ language extension that indicates a symbol is to be globally visible.
|
||||||
|
If the compiler has no such extension, the macro is defined with no replacement text.
|
||||||
|
Needed for classes that are not otherwise exported, but are used by RTTI. Examples include
|
||||||
|
class for objects that will be thrown as exceptions or used in dynamic_casts,
|
||||||
|
across shared library boundaries. For example, a header-only exception class might look like this:
|
||||||
|
``
|
||||||
|
class BOOST_SYMBOL_VISIBLE my_exception : public std::runtime_error { ... };
|
||||||
|
``
|
||||||
|
Without BOOST_SYMBOL_VISIBLE, it would be impossible to catch my_exception thrown from a shared library
|
||||||
|
compiled by GCC with the -fvisibility=hidden option.
|
||||||
|
]]
|
||||||
|
[[`BOOST_HAS_DECLSPEC`][
|
||||||
|
The compiler has C++ extensions `__declspec(dllexport)` and `__declspec(dllimport)` to control
|
||||||
|
export/import of symbols from shared libraries.
|
||||||
|
['Deprecated. This macro is no longer necessary since BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT
|
||||||
|
are now supplied. It is provided to support legacy code.]
|
||||||
|
]]
|
||||||
|
]
|
||||||
|
|
||||||
|
Typical usage:
|
||||||
|
|
||||||
|
[*boost/foo/config.hpp]
|
||||||
|
|
||||||
|
...
|
||||||
|
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FOO_DYN_LINK)
|
||||||
|
# if defined(BOOST_FOO_SOURCE)
|
||||||
|
# define BOOST_FOO_DECL BOOST_SYMBOL_EXPORT
|
||||||
|
# else
|
||||||
|
# define BOOST_FOO_DECL BOOST_SYMBOL_IMPORT
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define BOOST_FOO_DECL
|
||||||
|
#endif
|
||||||
|
...
|
||||||
|
|
||||||
|
[*boost/foo/foo.hpp]
|
||||||
|
|
||||||
|
#include <boost/foo/config.hpp>
|
||||||
|
...
|
||||||
|
class BOOST_FOO_DECL bar { ... };
|
||||||
|
...
|
||||||
|
void BOOST_FOO_DECL f();
|
||||||
|
...
|
||||||
|
|
||||||
|
[*boost/libs/foo/src/foo.cpp]
|
||||||
|
|
||||||
|
#define BOOST_FOO_SOURCE
|
||||||
|
#include <boost/foo/foo.hpp>
|
||||||
|
...
|
||||||
|
void BOOST_FOO_DECL f()
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[section ABI Fixing]
|
[section ABI Fixing]
|
||||||
|
|
||||||
|
@ -230,8 +230,9 @@
|
|||||||
//
|
//
|
||||||
// all versions support __declspec:
|
// all versions support __declspec:
|
||||||
//
|
//
|
||||||
#ifndef __STRICT_ANSI__
|
#if defined(__STRICT_ANSI__)
|
||||||
# define BOOST_HAS_DECLSPEC
|
// config/platform/win32.hpp will define BOOST_SYMBOL_EXPORT, etc., unless already defined
|
||||||
|
# define BOOST_SYMBOL_EXPORT
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
// ABI fixing headers:
|
// ABI fixing headers:
|
||||||
|
@ -18,12 +18,6 @@
|
|||||||
# define BOOST_NO_RTTI
|
# define BOOST_NO_RTTI
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__int32)
|
|
||||||
// HACK: Clang only defines the type __int32 in Microsoft-compatibility mode,
|
|
||||||
// which means that declspecs are also available
|
|
||||||
# define BOOST_HAS_DECLSPEC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__int64)
|
#if defined(__int64)
|
||||||
# define BOOST_HAS_MS_INT64
|
# define BOOST_HAS_MS_INT64
|
||||||
#endif
|
#endif
|
||||||
|
@ -147,8 +147,9 @@
|
|||||||
//
|
//
|
||||||
// all versions support __declspec:
|
// all versions support __declspec:
|
||||||
//
|
//
|
||||||
#if !defined(__STRICT_ANSI__)
|
#if defined(__STRICT_ANSI__)
|
||||||
# define BOOST_HAS_DECLSPEC
|
// config/platform/win32.hpp will define BOOST_SYMBOL_EXPORT, etc., unless already defined
|
||||||
|
# define BOOST_SYMBOL_EXPORT
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
// ABI fixing headers:
|
// ABI fixing headers:
|
||||||
|
@ -108,6 +108,28 @@
|
|||||||
#if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 )
|
#if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 )
|
||||||
#define BOOST_HAS_NRVO
|
#define BOOST_HAS_NRVO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// Dynamic shared object (DSO) and dynamic-link library (DLL) support
|
||||||
|
//
|
||||||
|
#if __GNUC__ >= 4
|
||||||
|
# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||||
|
// 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
|
||||||
|
# define BOOST_SYMBOL_EXPORT __attribute__((dllexport))
|
||||||
|
# define BOOST_SYMBOL_IMPORT __attribute__((dllimport))
|
||||||
|
# else
|
||||||
|
# define BOOST_SYMBOL_EXPORT __attribute__((visibility("default")))
|
||||||
|
# define BOOST_SYMBOL_IMPORT
|
||||||
|
# endif
|
||||||
|
# define BOOST_SYMBOL_VISIBLE __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
// config/platform/win32.hpp will define BOOST_SYMBOL_EXPORT, etc., unless already defined
|
||||||
|
# define BOOST_SYMBOL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// RTTI and typeinfo detection is possible post gcc-4.3:
|
// RTTI and typeinfo detection is possible post gcc-4.3:
|
||||||
//
|
//
|
||||||
|
@ -163,11 +163,6 @@
|
|||||||
# define BOOST_NO_RTTI
|
# define BOOST_NO_RTTI
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
|
||||||
// all versions support __declspec:
|
|
||||||
//
|
|
||||||
#define BOOST_HAS_DECLSPEC
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// C++0x features
|
// C++0x features
|
||||||
//
|
//
|
||||||
|
@ -21,10 +21,17 @@
|
|||||||
# define BOOST_NO_SWPRINTF
|
# define BOOST_NO_SWPRINTF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__GNUC__) && !defined(BOOST_HAS_DECLSPEC)
|
// Default defines for BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT
|
||||||
|
// If a compiler doesn't support __declspec(dllexport)/__declspec(dllimport),
|
||||||
|
// its boost/config/compiler/ file must define BOOST_SYMBOL_EXPORT and
|
||||||
|
// BOOST_SYMBOL_IMPORT
|
||||||
|
#ifndef BOOST_SYMBOL_EXPORT
|
||||||
# define BOOST_HAS_DECLSPEC
|
# define BOOST_HAS_DECLSPEC
|
||||||
|
# define BOOST_SYMBOL_EXPORT __declspec(dllexport)
|
||||||
|
# define BOOST_SYMBOL_IMPORT __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 2) || ((__MINGW32_MAJOR_VERSION == 2) && (__MINGW32_MINOR_VERSION >= 0)))
|
#if defined(__MINGW32__) && ((__MINGW32_MAJOR_VERSION > 2) || ((__MINGW32_MAJOR_VERSION == 2) && (__MINGW32_MINOR_VERSION >= 0)))
|
||||||
# define BOOST_HAS_STDINT_H
|
# define BOOST_HAS_STDINT_H
|
||||||
# define __STDC_LIMIT_MACROS
|
# define __STDC_LIMIT_MACROS
|
||||||
|
@ -25,6 +25,19 @@
|
|||||||
#ifndef BOOST_CONFIG_SUFFIX_HPP
|
#ifndef BOOST_CONFIG_SUFFIX_HPP
|
||||||
#define BOOST_CONFIG_SUFFIX_HPP
|
#define BOOST_CONFIG_SUFFIX_HPP
|
||||||
|
|
||||||
|
//
|
||||||
|
// ensure that visibility macros are always defined, thus symplifying use
|
||||||
|
//
|
||||||
|
#ifndef BOOST_SYMBOL_EXPORT
|
||||||
|
# define BOOST_SYMBOL_EXPORT
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_SYMBOL_IMPORT
|
||||||
|
# define BOOST_SYMBOL_IMPORT
|
||||||
|
#endif
|
||||||
|
#ifndef BOOST_SYMBOL_VISIBLE
|
||||||
|
# define BOOST_SYMBOL_VISIBLE
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// look for long long by looking for the appropriate macros in <limits.h>.
|
// look for long long by looking for the appropriate macros in <limits.h>.
|
||||||
// Note that we use limits.h rather than climits for maximal portability,
|
// Note that we use limits.h rather than climits for maximal portability,
|
||||||
|
Reference in New Issue
Block a user