问题
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=(
回答1:
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.
回答2:
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 git@gitorious.org:qt/qt5.git).
Hope this works for you too.
回答3:
I have just encountered the same problem and found helpfull info on the Qt-forum.
Here are Qt bugreport and Qt-forum thread with helpfull description and workarounds of the problem:
https://bugreports.qt-project.org/browse/QTBUG-29331
http://qt-project.org/forums/viewthread/22993/
来源:https://stackoverflow.com/questions/15056834/qt5-migration-and-boost-if-hpp-macro-argument-mismatch-bug