Search code examples
c++qtboostshared-librariesqtcore

Boost version of Qt qglobal.h


When using Qt Creator to create a library, it automatically generates a global header in which it defines the export symbols macro. This is an example code:

#ifndef LIB_GLOBAL_HPP
#define LIB_GLOBAL_HPP

#include <QtCore/qglobal.h>

#if defined(LIB)
#  define LIB_SHARED_EXPORT Q_DECL_EXPORT
#else
#  define LIB_SHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // LIB_GLOBAL_HPP

Is it possible to achieve the same platform independency using only the Boost library? I'd like to use Qt Creator without depending on Qt library.


Solution

  • While your snippet does not seem to be complete, as that is not enough definition for a stable library, this seems to be possible by boost, too, by almost applying one-by-one mapping, i.e. just different names:

    ...
    #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
    ...
    

    Please note that it also contains the additional logic that I was referring above; without that, it is not really a complete cross-platform solution. For further details, please refer to the boost documentation here.