PDA

View Full Version : Error compiling Qt3 app with Boost signals support



stodge
1st May 2007, 16:40
I wrote a simple Networking library that uses Boost on Linux (Fedora Core 6). I thought I'd try and add a Qt3 front end, but when I compile I get a weird error:


/usr/include/boost/signals/detail/signals_common.hpp:26: error: expected identifier before protected
/usr/include/boost/signals/detail/signals_common.hpp:26: error: expected unqualified-id before protected
main.cc:20: error: expected `}' at end of input


The Boost header file is:

http://boost.cvs.sourceforge.net/boost/boost/boost/signals/detail/signals_common.hpp?revision=1.11&view=markup

Any ideas?

bmesing
1st May 2007, 17:31
You are probably running into some precompiler problems. QT defines some macros, and they might conflict with boost method names. I had the same problem when using a library which used "sigc++". You have to make sure, that the boost headers are included, before QT defines their macros (emit, signal, slot,...).

For my project there is a file called "workarounds.h" which includes the relevant files. workarounds.h is included by giving the compiler a command line option "gcc -include workarounds.h". (Actually the solution was written by someone else, who helped me on my project).



#ifndef PACKAGESEARCH_WORKAROUNDS_H
#define PACKAGESEARCH_WORKAROUNDS_H

/*
* Workarounds for symbol clashes
*/

/*
* emit is a #define in qt and a method name in sigc++, so you have to include
* it before qt-anything
*/
#include <sigc++/sigc++.h>

/*
* QT makes use of a GC symbol, which is also defined by libgc, that gets
* included by wibble, that gets included by ept
*/
#define GC QT_GC_WORKAROUND
#include <qwindowdefs.h>
#include <qpainter.h>
#undef GC

#endif

stodge
1st May 2007, 18:42
That's what I thought - I include my own header file first in the Qt app I'm writing. It doesn't make a difference which order I include them.

Thanks

nmather
3rd May 2007, 10:48
Boost has an answer to this in their FAQ:

http://www.boost.org/doc/html/signals/s04.html#id2738878

We're using the latter solution in our project, and it seems to work fine so far.