GNOME Bugzilla – Bug 316726
Cannot compile gtkmm application
Last modified: 2006-06-19 20:39:46 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.
Do you have a test case?
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.
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.
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.
Re-opening on behalf of Javeed Shaikh, who provided a test case.
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.
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.
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.
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.)
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