Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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=(

like image 272
myWallJSON Avatar asked Feb 24 '13 21:02

myWallJSON


2 Answers

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.
like image 167
geomnerd Avatar answered Oct 25 '22 00:10

geomnerd


I have been struggling with the same problem and found that when I removed the definition of _MSC_VER=1700 from the custom build command for moc that the warning went away for me.

I was able to remove this from all the custom build moc steps by overriding the qmake.conf variable QMAKE_COMPILER_DEFINES. I am using a .pro file to generate a .vcxproj file and compiling my project using Visual Studio 2012 (Here is how to generate a .vcproj/.vcxproj file from a .pro file).

In the qmake.conf file associated with win32-msvc2012 this variable is as follows:

QMAKE_COMPILER_DEFINES += _MSC_VER=1700 _WIN32

In my .pro file I overrode it with this:

QMAKE_COMPILER_DEFINES = _WIN32

Then I regenerated the .vcxproj file and it compiled with no macro argument mismatch warnings.

I am using VS 2012, boost 1.51, and qt 5.1.2 (compiled from [email protected]:qt/qt5.git).

Hope this works for you too.

like image 29
j7peters Avatar answered Oct 25 '22 00:10

j7peters