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