After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 316726 - Cannot compile gtkmm application
Cannot compile gtkmm application
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.4
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2005-09-19 20:03 UTC by Mert Tugcu
Modified: 2006-06-19 20:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (41 bytes, text/plain)
2006-06-01 22:54 UTC, Javeed Shaikh
Details

Description Mert Tugcu 2005-09-19 20:03:53 UTC
Distribution/Version: Fedora Core 3

I am trying to compile an application that uses drawingarea. Here is the
compilation error:
g++ -O3 -o main main.cpp src/XvDisplayer.cpp src/dvcapture.cpp src/frame.cpp
src/ieee1394io.cpp  -I/usr/include/gtkmm-2.4 -I/usr/X11R6/include  -L.
-L/usr/X11R6/libs -lpthread -lXv -ldv `pkg-config gtkmm-2.4 --cflags --libs`
In file included from /usr/include/glibmm-2.4/glibmm/interface.h:24,
                 from /usr/include/glibmm-2.4/glibmm.h:38,
                 from /usr/include/gtkmm-2.4/gtkmm/drawingarea.h:6,
                 from src/../include/customdrawingarea.h:4,
                 from src/../include/XvDisplayer.h:17,
                 from src/XvDisplayer.cpp:1:
/usr/include/glibmm-2.4/glibmm/object.h:117: error: expected unqualified-id
before numeric constant
/usr/include/glibmm-2.4/glibmm/object.h:117: error: expected `)' before numeric
constant
/usr/include/glibmm-2.4/glibmm/object.h:118: error: expected identifier before
numeric constant
/usr/include/glibmm-2.4/glibmm/object.h:118: error: expected `,' or `...' before
numeric constant
/usr/include/glibmm-2.4/glibmm/object.h:118: error: ISO C++ forbids declaration
of `parameter' with no type
In file included from /usr/include/gdkmm-2.4/gdkmm/gc.h:31,
                 from /usr/include/gdkmm-2.4/gdkmm/drawable.h:33,
                 from /usr/include/gdkmm-2.4/gdkmm/window.h:27,
                 from /usr/include/gdkmm-2.4/gdkmm/event.h:28,
                 from /usr/include/gtkmm-2.4/gtkmm/widget.h:31,
                 from /usr/include/gtkmm-2.4/gtkmm/drawingarea.h:29,
                 from src/../include/customdrawingarea.h:4,
                 from src/../include/XvDisplayer.h:17,
                 from src/XvDisplayer.cpp:1:
/usr/include/gdkmm-2.4/gdkmm/types.h:186: error: expected identifier before "int"
/usr/include/gdkmm-2.4/gdkmm/types.h:187: error: expected unqualified-id before
'{' token
/usr/include/gdkmm-2.4/gdkmm/types.h:187: error: expected `,' or `;' before '{'
token
/usr/include/gdkmm-2.4/gdkmm/types.h:203: error: missing `>' to terminate the
template argument list
/usr/include/gdkmm-2.4/gdkmm/types.h:203: error: template argument 1 is invalid
/usr/include/gdkmm-2.4/gdkmm/types.h:203: error: expected unqualified-id before
'>' token
/usr/include/gdkmm-2.4/gdkmm/types.h:203: error: expected `;' before '>' token
make: *** [main] Error 1

All my header files have #ifndef and #define statements.
Comment 1 Murray Cumming 2005-09-26 12:24:27 UTC
Do you have a test case?
Comment 2 Mert Tugcu 2005-09-27 01:48:13 UTC
Yes I do have a test case. I am trying to show DV camera stream in my 
application. There are a lot of files tough. I can send an e-mail along with 
the source files attached if you like. Let me know thx.
Comment 3 Murray Cumming 2005-09-27 05:35:04 UTC
A test case should be as simple as possible. In the process of creating that
simple test case you will probably discover the error. Please reopen this bug if
you create a test case.

For instance, some other header might be #define-ing something that breaks the
gtkmm headers.
Comment 4 Javeed Shaikh 2006-06-01 22:54:14 UTC
Created attachment 66628 [details]
Test case

This is a test case.
Compile it with g++ -Wall -pedantic -c test.h `pkg-config --cflags gdkmm-2.4`
(it won't compile.)
The problem is solved if the order of the two header files is swapped. I was pulling my hair out trying to fix this.
I think something should be done about this.
Comment 5 Karsten Bräckelmann 2006-06-01 23:32:43 UTC
Re-opening on behalf of Javeed Shaikh, who provided a test case.
Comment 6 Murray Cumming 2006-06-02 07:19:16 UTC
Excellent detective work.

Does this happen also with gtk.h instead of gtkmm.h? Then we can reassign it to GTK+. Maybe they (or us, if necessary) could add a compiler warning to prevent it.
Comment 7 Javeed Shaikh 2006-06-02 15:42:40 UTC
This does not happen with the non-mm gtk.h, glib.h, or gdk.h.
It does happen with gtkmm.h (because it brings in glibmm.h and gdkmm.h), glibmm.h, and gdkmm.h.

The problem with the glibmm.h header is that DestroyNotify being defined as a constant by Xlib (I believe it is used for events.)

The problem with gdkmm.h is that it brings in gdkmm/types.h, which the compiler does not like because the name of the enum on line 187 (Status) is also used by Xlib (I'm not quite sure what for, but grepping the header file gives many lines.)

This is a bit "fudgy", because the Status enum is inside the Gdk namespace. Unfortunately, the preprocessor doesn't really speak C++ (as far as I know), and it just replaces it with the numeric constant.
Comment 8 Murray Cumming 2006-06-02 18:29:09 UTC
Ah, well done. So, at those points in the headers, we need some kind of 

#ifdef DestroyNotify
#error "X11/Xlib.h seems to have been included before this header. Due to some commonly-named macros in X11/Xlib.h, it must be included after any glibmm/gdkmm/gtkmm headers".
#endif //DestroyNotify

I'm not sure whether #error can be used, but I think I've seen #warning before.
Comment 9 Javeed Shaikh 2006-06-08 17:59:24 UTC
Something of the sort would indeed help immensely.
To be honest, I have to blame Xlib for horrible namespace pollution(they could've done similar to what gtk does, prefixing everything.)
Comment 10 Murray Cumming 2006-06-19 20:39:46 UTC
Done in cvs. Now we see output like this:

murrayc@ubuntumurrayc:~/cvs/gnome216$ g++ testx11.cc `pkg-config gtkmm-2.4 --libs --cflags`
In file included from /opt/gnome216/include/glibmm-2.4/glibmm/interface.h:24,
                 from /opt/gnome216/include/glibmm-2.4/glibmm.h:38,
                 from /opt/gnome216/include/gdkmm-2.4/gdkmm/types.h:7,
                 from /opt/gnome216/include/gdkmm-2.4/gdkmm.h:27,
                 from testx11.cc:2:
/opt/gnome216/include/glibmm-2.4/glibmm/object.h:26:4: error: #error "X11/Xlib.h seems to have been included before this header. Due to some commonly-named macros in X11/Xlib.h, it may only be included after any glibmm, gdkmm, or gtkmm headers."
/opt/gnome216/include/glibmm-2.4/glibmm/object.h:126: error: expected unqualified-id before numeric constant
/opt/gnome216/include/glibmm-2.4/glibmm/object.h:126: error: expected `)' before numeric constant
/opt/gnome216/include/glibmm-2.4/glibmm/object.h:127: error: expected identifier before numeric constant
/opt/gnome216/include/glibmm-2.4/glibmm/object.h:127: error: expected ‘,’ or ‘...’ before numeric constant
/opt/gnome216/include/gdkmm-2.4/gdkmm/types.h:187: error: expected identifier before ‘int’
/opt/gnome216/include/gdkmm-2.4/gdkmm/types.h:188: error: expected unqualified-id before ‘{’ token
/opt/gnome216/include/gdkmm-2.4/gdkmm/types.h:204: error: template argument 1 is invalid
/opt/gnome216/include/gdkmm-2.4/gdkmm/types.h:204: error: template argument 1 is invalid