19

I'm getting the error Parse error at "BOOST_JOIN" while trying to compile a code with Qt4 and CGAL. I'm not using Boost directly and I've already searched and tried a bunch of options like -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDEDand -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION. The versions I'm working with are CGAL 4.1.0, Qt 4.8.4_6 and Boost 1.53.0_1, and using CMake to generate the Makefile, in a machine Mac OS 10.8.2. Any ideas of what could be causing that error?

Mauricio Zambon
  • 695
  • 2
  • 9
  • 17

3 Answers3

21

This problem happens in Boost 1.56.0 with QT 4.7.4 (which is quite old now),

Regardless, another quick workaround is to edit the problematic boost header files, and

add to the top:
#ifndef Q_MOC_RUN

add to the bottom:
#endif

This will at least let MOC run without dying.

elegant dice
  • 1,307
  • 12
  • 19
  • 1
    As an addition: The `#ifndef Q_MOC_RUN .. #endif` statement has to encapsulate all boost-related includes in your code. It should not encapsulate Qt or STL-includes. – Tones29 Jul 18 '17 at 13:39
18

When you compile a piece of code that defines Qt objects, the build system needs to call the Qt Meta Object Compiler, aka "moc". In Qt versions before 5.0, the "moc" compiler (actually a precompiler) does not parse correctly all C++ code. In particular, it does not fully expand preprocessor macros. In recent Boost versions, some macros (like that BOOST_JOIN) are sometimes used to define a namespace name. For example:

namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) {

in boost/type_traits/detail/has_binary_operator.hpp of Boost version 1.53.

A Qt bug has being filled at Qt-Project.org and is said to be fixed in Qt-5.0.

In CGAL-4.2, I have tried to suppress those build errors by separating more the use of Qt and Boost in different compilation units. You should retry with a recent version of Boost, and CGAL-4.2-beta1 (or later versions if they are released when you read that answer). Let me know if you encounter similar problems with CGAL-4.2-beta1 or later.

As for Qt-5.0, I hope CGAL-4.3 will support it. We will have to work on the CMake scripts to support it. It will be added to the planning of the next CGAL developers meeting.

lrineau
  • 6,036
  • 3
  • 34
  • 47
  • 1
    "In Qt versions before 5.0, the "moc" compiler (actually a precompiler) does parse correctly all C++ code" - you mean it does _not_ correctly parse all code, I think. – davmac Jan 18 '15 at 12:42
  • @davmac Thanks. +1 to your comment. I have modified the answer accordingly. It is strange that that typo was unnoticed until then. – lrineau Jan 20 '15 at 11:35
6

I downgraded to Boost 1.52, and now it's compiling.

Mauricio Zambon
  • 695
  • 2
  • 9
  • 17