[Boost-bugs] [Boost C++ Libraries] #4959: Linking Serialization static lib to a DLL breaks auto-import in MinGW

Subject: [Boost-bugs] [Boost C++ Libraries] #4959: Linking Serialization static lib to a DLL breaks auto-import in MinGW
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-12-07 23:23:19


#4959: Linking Serialization static lib to a DLL breaks auto-import in MinGW
-----------------------------------+----------------------------------------
 Reporter: jlcastillo@… | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: |
-----------------------------------+----------------------------------------
 With MinGW GCC 4.51 and Boost 1.45, boost being compiled with the
 following command line:

 {{{
 bjam toolset=gcc --build-type=complete --threading=multi variant=release
 link=static runtime-link=shared stage --stagedir=$RELEASE_LIB_DIR -j2
 bjam toolset=gcc --build-type=complete --threading=multi variant=debug
 link=static runtime-link=shared stage --stagedir=$DEBUG_LIB_DIR -j2
 }}}

 The static serialization lib attaches "declspec(dllexport)" to some
 methods in boost/serialization/singleton.hpp, i.e. get_mutable_instance,
 get_const_instance and is_destroyed.

 This is OK if we link the static library against an executable. If we
 however link it against a DLL, GCC stops exporting automatically all the
 symbols in the source code of the DLL (auto-import feature), and switches
 to a linking mode where only those functions declared with
 "declspec(dllexport)" are exported.

 This is very inconvenient and hard to track if you use an automatic build
 environment like Boost Build (bjam).

 We fixed it adding the following lines to
 /boost/serialization/force_include.hpp:

 {{{
 #if defined(BOOST_HAS_DECLSPEC) && !defined(__COMO__)
 # if defined(__BORLANDC__)
 # define BOOST_DLLEXPORT __export
 # elif defined(__MINGW32__) // JOSE FIX !!!!
 # if defined(__GNUC__) && (__GNUC__ >= 3)
 # define BOOST_USED __attribute__ ((used))
 # endif
 # else
 # define BOOST_DLLEXPORT __declspec(dllexport)
 # endif
 #elif ! defined(_WIN32) && ! defined(_WIN64)
 # if defined(__MWERKS__)
 # define BOOST_DLLEXPORT __declspec(dllexport)
 # elif defined(__GNUC__) && (__GNUC__ >= 3)
 # define BOOST_USED __attribute__ ((used))
 # elif defined(???????) && (?????? >= 1110)
 # define BOOST_USED __attribute__ ((used))
 # elif defined(__INTEL_COMPILER) && (BOOST_INTEL_CXX_VERSION >= 800)
 # define BOOST_USED __attribute__ ((used))
 # endif
 #endif
 }}}

 You need to recompile the Boost Serialization static library with these
 changes, and make sure you have the modified force_include.hpp in the
 boost include that your apps use during compilation.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4959>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC