Alex Rivera | Logout

QT5 migration and Boost: if.hpp: Macro argument mismatch bug

Asked 2013-02-24T21:24:56.117
8

In qt 4.8 I used boost (1.52) It all was ok... Now I try to move to QT5 and get if.hpp: Macro argument mismatch error on line 131 BOOST_MPL_AUX_NA_SPEC(3, if_). In some QT forums there is presented a solution like this:

#ifndef Q_MOC_RUN
// All boost includes
#endif // Q_MOC_RUN

in each my file that uses boost... So question here is - how to tell to boost that QT is not ready for BOOST_MPL_AUX_NA_SPEC and that boost shall use some more primitive preprocessor syntax one that would be QT5 compatible?


Update: found this solution yet it seems not to bring any effect at all in Qt5=(

Edit
Report

1 Answer

6

Here is the best workaround I've been able to find after scouring the net for a few hours. It is basically what other folks have been saying, but with a few clarifications.

  • The problem has to do with moc.exe not correctly handling Boost macros.
  • In order to get around this, we disable inclusion of Boost headers by defining their include guards for the moc.exe process, but not for regular source compilation.
  • This can be accomplished most easily by adding the following code to your project file (e.g. myproject.pro):

    # ensure QMAKE_MOC contains the moc executable path
    load(moc) 
    
    # for each Boost header you include...
    QMAKE_MOC += -DBOOST_INCLUDE_GUARD_GOES_HERE 
    

For example, if I want to use the logging library, I'd have:

#include <boost/log/trivial.hpp>

If I open up the header file, I can see at the top that the include guard is named BOOST_LOG_TRIVIAL_HPP_INCLUDED_. Therefore, the corresponding line in the .pro file would read:

QMAKE_MOC += -DBOOST_LOG_TRIVIAL_HPP_INCLUDED_

A couple of more notes in case they are relevant for anyone:

  • If you find this not working, make sure to run qmake and rebuild your project whenever you add a new line to your project file.
  • I'm using Boost 1.53 with Qt 5.0.1 and building for MSVC2010 within QtCreator on Windows 7 32-bit.
answered 2013-05-24T01:40:43.970

Your Answer