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=(
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With