GNOME Bugzilla – Bug 343741
Gdk::Window missing 'create_cairo_context' in "drawingarea/simple" tutorial example code
Last modified: 2006-06-04 22:58:17 UTC
Overview Description: While trying to compile the example from "Drawing Straight Lines" in Chapter 15 of the gtkmm-2.4 tutorial, the compiler gave me this error message: myarea.cc: In member function 'virtual bool MyArea::on_expose_event(GdkEventExpose*)': myarea.cc:45: error: 'class Gdk::Window' has no member named 'create_cairo_context' The example in question is presented at http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch15s02.html and the code comes from http://www.gtkmm.org/docs/gtkmm-2.4/examples/book/drawingarea/simple . Steps to Reproduce: 1) Install latest gtkmm RPMs from Fedora Core 4 "Extras" repository: libsigc++20.i386 2.0.11-1 libsigc++20-devel.i386 2.0.11-1 glibmm24.i386 2.6.1-1 glibmm24-devel.i386 2.6.1-1 gtkmm24.i386 2.6.2-2 gtkmm24-devel.i386 2.6.2-2 gtkmm24-docs.i386 2.6.2-2 gtkglext.i386 1.0.6-2 gtkglext-devel.i386 1.0.6-2 2) Install latest cairo (1.0.4) and cairomm (0.6.0) from source tarballs. (I could not find cairomm available as an RPM.) 3) Download example code from http://www.gtkmm.org/docs/gtkmm-2.4/examples/book/drawingarea/simple/* (The files are: myarea.h myarea.cc main.cc) 4) Compile with command: g++ main.cc myarea.cc -o drawingarea `pkg-config cairo cairomm-1.0 gtkmm-2.4 --cflags --libs` (The pkg-config part expands to: -DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API -I/usr/local/include/cairo -I/usr/local/include/cairomm-1.0 -I/usr/include/gtkmm-2.4 -I/usr/lib/gtkmm-2.4/include -I/usr/include/glibmm-2.4 -I/usr/lib/glibmm-2.4/include -I/usr/include/gdkmm-2.4 -I/usr/lib/gdkmm-2.4/include -I/usr/include/pangomm-1.4 -I/usr/include/atkmm-1.6 -I/usr/include/gtk-2.0 -I/usr/include/sigc++-2.0 -I/usr/lib/sigc++-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/include/atk-1.0 -L/usr/local/lib -lcairomm-1.0 -lcairo -lgtkmm-2.4 -lgdkmm-2.4 -latkmm-1.6 -lgtk-x11-2.0 -lpangomm-1.4 -lglibmm-2.4 -lsigc-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 ) 5) Notice error. Actual Results: Compiler complains: myarea.cc: In member function 'virtual bool MyArea::on_expose_event(GdkEventExpose*)': myarea.cc:45: error: 'class Gdk::Window' has no member named 'create_cairo_context' (This is the entire output of the compiler.) Expected Results: Program compiles and learning continues. Build Date & Platform: Platform: Fedora Core 4 (all packages kept up to date) Compiler: g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8) Build dates: libsigc++20.i386 2.0.11-1 Thu 05 May 2005 04:12:26 AM CDT libsigc++20-devel.i386 2.0.11-1 Thu 05 May 2005 04:12:26 AM CDT glibmm24.i386 2.6.1-1 Thu 05 May 2005 04:24:00 AM CDT glibmm24-devel.i386 2.6.1-1 Thu 05 May 2005 04:24:00 AM CDT gtkmm24.i386 2.6.2-2 Thu 05 May 2005 04:47:40 AM CDT gtkmm24-devel.i386 2.6.2-2 Thu 05 May 2005 04:47:40 AM CDT gtkmm24-docs.i386 2.6.2-2 Thu 05 May 2005 04:47:40 AM CDT gtkglext.i386 1.0.6-2 Thu 07 Apr 2005 01:19:56 PM CDT gtkglext-devel.i386 1.0.6-2 Thu 07 Apr 2005 01:19:56 PM CDT Additional Builds and Platforms: Unknown. Additional Information: Before installing cairomm, there were many more errors, as apparently the Cairo related classes/libraries could not be found. This error seems to be with gtkmm or the tutorial example, not with cairo/cairomm.
Thanks for reporting this, but this is not actually a bug. create_cairo_context() was introduced in gtkmm 2.9.x, so it won't be available in previous versions (2.6.x in your case). I suggest that you look at the documentation that you installed (gtkmm24-docs.i386 2.6.2-2) for the tutorial that applies to your version of gtkmm. I apologize that this was not made more clear in the online documentation.
(In reply to comment #1) > Thanks for reporting this, but this is not actually a bug. > create_cairo_context() was introduced in gtkmm 2.9.x, so it won't be available > in previous versions (2.6.x in your case). I suggest that you look at the > documentation that you installed (gtkmm24-docs.i386 2.6.2-2) for the tutorial > that applies to your version of gtkmm. Thanks for the information, and for the suggestion. I actually hadn't thought of looking at the installed docs! > > I apologize that this was not made more clear in the online documentation. > Would it make sense for me to submit a bug report about the documentation being less-than-clear?
> Would it make sense for me to submit a bug report about the documentation being > less-than-clear? Well, I'm trying to think of a good way to do this. In fact the drawing area chapter in the tutorial already has this note: --- Note Before gtkmm version 2.10, drawing was mostly done with Graphics Contexts (Gdk::GC) and other GDK drawing functions, but this has been largely superceded by the Cairo graphics library and its C++ binding Cairomm. See the Gdk Appendix for a description of the deprecated GDK techniques. In general, the Cairo drawing API is simpler than the GDK one, and it is generally recommended to use the Cairo drawing methods wherever possible in preference to the older GDK drawing methods. --- Do you think something more obvious is needed?
(In reply to comment #3) > > Would it make sense for me to submit a bug report about the documentation being > > less-than-clear? > > Well, I'm trying to think of a good way to do this. In fact the drawing area > chapter in the tutorial already has this note: > > --- > Note > > Before gtkmm version 2.10, drawing was mostly done with Graphics Contexts > (Gdk::GC) and other GDK drawing functions, but this has been largely superceded > by the Cairo graphics library and its C++ binding Cairomm. See the Gdk Appendix > for a description of the deprecated GDK techniques. In general, the Cairo > drawing API is simpler than the GDK one, and it is generally recommended to use > the Cairo drawing methods wherever possible in preference to the older GDK > drawing methods. > --- > > Do you think something more obvious is needed? > Well, I was confused by that Note (and probably therefore initially ignored it), because I thought I was looking at the documentation for the gtkmm library, version 2.4, not 2.10. After all, the URL always has .../gtkmm-2.4/... in it. I didn't see what version 2.10 had to do with anything. After messing around with gtkmm and the website for a while, I think I finally understand that two different version numbers are involved: the API version, and the library version. The distinction was not initially clear to this newbie, however. (I'm not a programming newbie, but more of a newbie to open source programming libraries, and definitely to GTK, gtkmm, etc.) While it does say "This documentation is for the gtkmm 2.4 and gnomemm 2.6 APIs." at the top of http://www.gtkmm.org/docs/gtkmm-2.4/docs/, perhaps it should *also* say something like: "This means any version of the gtkmm library 2.4 through 2.10." (or whatever version numbers) Or maybe: "If you are using a version of the gtkmm library below 2.10, these docs may not apply to you." Whichever is the case. Also, in the tutorial, perhaps another disclaimer like: "Some chapters of the tutorial may apply to all versions of the gtkmm library, from 2.4 through 2.10, while some may apply only to newer versions of the library. Please also see the tutorial accompanying your version of the gtkmm library for information more specific to you." And perhaps each chapter or section could indicate specifically which library versions should work with it. At least this would give more of a heads-up to newbies (who I would expect to be looking at the tutorial) that what they are looking at may not apply to their situation. As for that note in Chapter 15, I notice that the appendix it refers to appears to be missing a lot of information about GDK that is in Chapter 14 of the tutorial I have installed locally (somewhat analogous to Chapter 15 of the online tutorial). Why not keep those extra sections in that appendix for people with older versions of the gtkmm library? I hope this helps in some small way.