Qt4 + CGAL - Parse error at "BOOST_JOIN"
Asked Answered
E

3

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?

Elgar answered 16/3, 2013 at 21:57 Comment(0)
W
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.

Waldack answered 8/8, 2014 at 1:37 Comment(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.Questionable
D
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.

Deceive answered 18/3, 2013 at 10:15 Comment(2)
"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.Traveler
@Traveler Thanks. +1 to your comment. I have modified the answer accordingly. It is strange that that typo was unnoticed until then.Deceive
E
6

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

Elgar answered 17/3, 2013 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.