Question

I compile a Qt executable using qmake && make on the following project.pro file:

INCLUDEPATH *= ../../dependencies/boost
QT *= opengl xml
CONFIG *= qt opengl static

TARGET = myexe
HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp
SOURCES = main.cpp Viewer.cpp MainWindow.cpp Inspector.cpp

However, when compiling, moc chokes on a boost macro which it cannot parse. To work around this bug, I need to pass the flag -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED to moc, but I cannot manage to do so.

How to I edit my .pro file to pass a given flag to moc? (but not to g++, as QMAKE_CXXFLAGS does)

Was it helpful?

Solution

A bit hackish, but what about if you overwrite the moc compiler so that it includes the flag. In the .pro:

QMAKE_MOC = $$QMAKE_MOC -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

OTHER TIPS

In my code in header files I just have:

#ifndef Q_MOC_RUN
    //Here we include Boost or Ogre headers with Macro
#endif

It works perfectly in Qt5 x64 and need not recompiling anything.

There is an update to this issue for boost 1.53, see the last post here:

We need to add -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION also.

For add specific flags to moc in a qmake project(qt5.2) need:

    load(moc)
    QMAKE_MOC += -DBOOST_INCLUDE_GUARD_GOES_HERE

See for example the Qmake docs for variables which details

  • ten different variables in the QMAKE_CFLAGS_* pattern, and

  • ten different variables in the QMAKE_CXXFLAGS* pattern

and hence I would start with QMAKE_CXXFLAGS which is documented as:

QMAKE_CXXFLAGS

This variable contains the C++ compiler flags that are used when building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified. The flags specific to debug and release modes can be adjusted by modifying the QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE variables, respectively. Note: On the Symbian platform, this variable can be used to pass architecture specific options to each compiler in the Symbian build system. For example:

QMAKE_CXXFLAGS.CW += -O2
QMAKE_CXXFLAGS.ARMCC += -O0 

For more information, see qmake Platform Notes.

So I'd start with

QMAKE_CXXFLAGS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

which you can just add to your .pro file.

In case you are doing Ogre3D (OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit) ) then use QT5 32bit instead of the QT5 64bit version, it will pass.

Also consider this :

#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif

I think it has been compiled (boost included) with 32bit thus i suppose i have to take src and recompile (using my 64bit) but thats another story where i wont go for now since OGRE 1.9 RC 1 SDK for Visual C++ .Net 2012 (64-bit) will be soon release on stable version.

Regards

EDIT 1 :

Downloaded Qt libraries 4.8.4 for Windows and configured my QT creator (the one coming with full QT5 and guess what …. Ogre3D is working like a charm when compiling on 4.8.4.

Qt 5.0.2 for Windows 32-bit (VS 2010, 485 MB)
Qt libraries 4.8.4 for Windows (VS 2010, 234 MB)
OGRE 1.8.1 SDK for Visual C++ .Net 2010 (32-bit)

I also mentionned it for who is interested here : http://qt-project.org/forums/viewreply/128660/

The best way I found to do this is based on a comment on the accepted solution from David Faure:

QMAKE_MOC_OPTIONS += -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED

The other proposed methods that involve load(moc) and manipulating the QMAKE_MOC variable itself have an unfortunate side effect: they prevent qmake from automatically adding INCLUDEPATH variables (and maybe others) that would normally be on moc's command line, if INCLUDEPATH is set up after the call to load(moc).

This approach composes easier if you have your qmake configuration split up to multiple files; you don't need to ensure that the change to the moc command line comes after all INCLUDEPATH directories are set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top