# GDK#create\_cairo\_context not found

**URL:** <https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247>\
**Category:** Ruby\
**Created:** [July 27, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247 "2006-07-27T23:50:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 27, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/1 "2006-07-27T23:50:58Z")

</div>

What version of rcairo, and ruby-gnome2 do I need to have  
GDK#create\_cairo\_context? I get the following error

demo.rb:23:in `expose': undefined method`create\_cairo\_context’ for  
#\<Gdk::Window:0xb724dd28 ptr=0x82bb290\> (NoMethodError)  
from demo.rb:13:in `initialize’  
from demo.rb:74

when trying to run the following sample code:  
#!/usr/bin/env ruby

require ‘cairo’  
require ‘gtk2’  
include Math

class DemiCercle \< Gtk::DrawingArea  
attr\_accessor :desp  
def initialize  
super  
add\_events(Gdk::Event::BUTTON\_PRESS\_MASK |  
Gdk::Event::BUTTON1\_MOTION\_MASK)  
signal\_connect “expose\_event” do |widget,event|  
expose(widget,event)  
end # do  
signal\_connect “button\_press\_event” do |widget,event|  
pressing(widget,event) end  
signal\_connect “motion\_notify\_event” do |widget,event|  
moving(widget,event) end

```
@desp = 0.0

```

end # initialize

def expose(widget,event)  
# crÃ©er un contexte graphique  
context = widget.window.create\_cairo\_context

```
context.rectangle(event.area.x, event.area.y,
                  event.area.width, event.area.height)

context.clip()
draw(context)
return false

```

end # expose

def draw(context)  
rect = allocation()  
x = rect.x + rect.width / 2.0  
y = rect.y + rect.height / 2.0

```
radius = [rect.width / 2.0, rect.height / 2.0].min - 5.0

#context.arc(x, y, radius, 0,(1 * PI))
context.arc(x, y, radius, 0 + @desp , (1.0 * PI) + @desp)

context.set_source_rgb(0.7, 0.8, 0.1)
context.fill_preserve()

context.set_source_rgb(0, 0, 0)
context.stroke()

```

end

def pressing(widget,event)  
pressing\_x = event.x  
end

def moving(widget,event)  
if (pressing(widget,event) - event.x) \> 1  
@desp = @desp + 0.2  
else  
@desp = @desp - 0.1  
end  
draw(widget.window.create\_cairo\_context)  
queue\_draw()  
end  
end

Gtk.init  
fen = Gtk::Window.new  
fen.set\_title(“Cairo exemple 2”)  
fen.signal\_connect(“destroy”) { Gtk.main\_quit }  
figure = DemiCercle.new  
fen.add(figure)  
fen.show\_all

Gtk.main

I have the following libs installed on my Gentoo box:

nicodemus portage # emerge -p rcairo gtk+ ruby-gnome2  
Calculating dependencies… done!  
[ebuild R] dev-ruby/rcairo-1.0.0 USE="-examples\*"  
[ebuild R] x11-libs/gtk±2.8.12 USE="-tiff\*"  
[ebuild R] dev-ruby/ruby-gnome2-0.14.1

Thank,  
Farrel

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 2:53pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/2 "2006-07-28T14:53:29Z")

</div>

do you get the same error in irb when you type  
require ‘cairo’

cairo has a list and they may be able to help,

If you have trouble with cairo or rcairo, or you have some ideas for  
how  
it could be improved, please feel free to send a message to the cairo  
mailinglist at removed\_email\_address@domain.invalid , which is archived at

[http://cairographics.org/cgi-bin/mailman/listinfo/cairo](http://cairographics.org/cgi-bin/mailman/listinfo/cairo)

a post from  
[http://lists.freedesktop.org/archives/cairo/2006-April/006663.html](http://lists.freedesktop.org/archives/cairo/2006-April/006663.html)  
refers to  
Gdk::Drawable::create\_cairo\_context()

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 3:23pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/3 "2006-07-28T15:23:03Z")

</div>

On 28/07/06, anne001 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> do you get the same error in irb when you type  
> require ‘cairo’

Nope cairo loads fine. It just seems that the GDK::Drawable object  
seems to be missing the create\_cairo\_context method. According to the  
documentation I’ve read that code should work with GTK 2.8,  
Ruby/Gnome2 0.14 and rcairo 1.0 all of which I have installed. I’ve  
recompiled and re-installed everything but that didn’t work. I just  
want to make sure that I’m using the correct versions or if I’m not  
missing some other required library.

Thanks,  
Farrel

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/4 "2006-07-28T23:27:07Z")

</div>

On 28/07/06, Masao M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you are’t be able to fix it,  
> show me your ruby-gnome2-x.x.x/gtk/mkmf.log.

Hi,

I solved the problem I had to re-install the ruby/gtk2 bindings after  
I had installed rcairo.

Thanks for the help,  
Farrel

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/5 "2006-07-28T18:36:25Z")

</div>

Hi,

Your sample works on my machine.

I suspect you didn’t install Ruby/Cairo devel package.

Check /usr/(local/)lib/ruby/site\_ruby/1.8/i686-linux/rb\_cairo.h.  
If it’s not existed, you need to install Ruby/Cairo dev package  
first. Then compile Ruby-GNOME2 again.

If you are’t be able to fix it,  
show me your ruby-gnome2-x.x.x/gtk/mkmf.log.

On Fri, 28 Jul 2006 22:20:50 +0900

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 11:33pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/6 "2006-07-28T23:33:16Z")

</div>

With a little help, I managed to compile cairo on my OS X such that irb  
can include cairo without error message. So now, I get the same error  
message as Farrel

I checked on rb\_cairo.h, it is in  
/private/opt/local/lib/ruby/site\_ruby/1.8/powerpc-darwin8.3.0/rb\_cairo.h

The person who helped me with my cairo installed thought that the  
problem was with my having an old gnome2, but the darwinport folder  
said ruby-gnome2-all-0.15.0. he thought 0.15.0 was alright.

he suggested getting help at

> **[ruby-gnome2-devel-en List Signup and Options](https://sourceforge.net/projects/ruby-gnome2/lists/ruby-gnome2-devel-en)**
>
> This project is a set of Ruby language bindings for the various application development libraries included with the GNOME/GTK+ environment.
> This…

I found the ruby-gnome2-all-0.15.0/gtk/mkmf.log, I posted it at  
visionlab.harvard.edu/Members/Anne/mkmf.log

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 28, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/7 "2006-07-28T23:56:35Z")

</div>

So it is an install problem.

I was interested, because I wanted to know if my gnome2 install was ok,  
I guess not. I tried recompiling all the rb files, but that did not  
change anything for me. glib2, atk, cairo, pango and then gtk, but I  
still have the error. Oh well.

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 29, 2006, 4:39am UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/8 "2006-07-29T04:39:18Z")

</div>

Hi,

On Sat, 29 Jul 2006 06:30:06 +0900  
“anne001” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> he suggested getting help at  
> [ruby-gnome2-devel-en List Signup and Options](http://lists.sourceforge.net/mailman/listinfo/ruby-gnome2-devel-en)
> 
> I found the ruby-gnome2-all-0.15.0/gtk/mkmf.log, I posted it at  
> visionlab.harvard.edu/Members/Anne/mkmf.log

It seems no problem from your mkmf.log.  
rb\_cairo.h was found in it correctly.

You need to tell us more informations.

1. What is the result of require ‘cairo’ ?  
$ irb  
irb(main):001:0\> require ‘cairo’  
=\> true

2. Try to remove /private/opt/local/lib/ruby/site\_ruby/1.8/…/gtk2.so  
once, then,  
$ cd ruby-gnome2-x.x.x/gtk  
$ make clean  
$ ruby extconf.rb \>& log.txt  
$ make \>\>& log.txt  
$ make install \>\>& log.txt

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 29, 2006, 4:46pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/9 "2006-07-29T16:46:04Z")

</div>

> 1. What is the result of require ‘cairo’ ?  
> $ irb  
> irb(main):001:0\> require ‘cairo’  
> =\> true  
> that is correct

> 1. Try to remove /private/opt/local/lib/ruby/site\_ruby/1.8/…/gtk2.so

I can’t find such a file with EasyFind. On the web I see references to  
/usr/local/lib/ruby/site\_ruby/1.8/i386-freebsd4/gtk2.so  
site\_ruby/1.8/i586-linux-gnu/gtk2.so  
site\_ruby/1.8/i586-linux/gtk2.so  
usr/lib/ruby/1.8/i386-linux/gtk2.so

ls /private/opt/local/lib/ruby/site\_ruby/1.8 anne$ ls  
#hhp-access2.rb# gtk2 pango.rb  
atk.rb gtk2.rb pkg-config.rb  
cairo.rb gtkglext.rb powerpc-darwin8.3.0  
gconf2.rb gtkhtml2.rb soap  
gdk\_pixbuf2.rb http-access2 universal-darwin8.0  
glib2.rb http-access2.rb web  
gnome2.rb http-access2.rb~ web.rb  
gnomecanvas2.rb libglade2.rb wsdl  
gnomevfs.rb mkmf-gnome2.rb xmlscan

powerpc-darwin8.3.0 has bundles and .h files.

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 29, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/10 "2006-07-29T17:10:44Z")

</div>

Hi,

On Sat, 29 Jul 2006 23:45:11 +0900  
“anne001” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 1. What is the result of require ‘cairo’ ?  
> > $ irb  
> > irb(main):001:0\> require ‘cairo’  
> > =\> true  
> > that is correct
> 
> > 1. Try to remove /private/opt/local/lib/ruby/site\_ruby/1.8/…/gtk2.so
> 
> I can’t find such a file with EasyFind. On the web I see references to

You must have “gtk2.so” anywhere. Find it and remove all of “gtk2.so”.

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 29, 2006, 12:26am UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/11 "2006-07-29T00:26:20Z")

</div>

On 28/07/06, anne001 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So it is an install problem.
> 
> I was interested, because I wanted to know if my gnome2 install was ok,  
> I guess not. I tried recompiling all the rb files, but that did not  
> change anything for me. glib2, atk, cairo, pango and then gtk, but I  
> still have the error. Oh well.

It helped me that I built ruby/gtk2 after I had installed rcairo.

Farrel

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 29, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/12 "2006-07-29T22:36:49Z")

</div>

from what I read .so is an extension for a shared library.

The extension for a shared library on Mac OS X is .dylib, so this  
shared library is named mymfunction.dylib on Mac OS X. This book uses  
.so as the extension for UNIX shared libraries, so Mac OS X users need  
to use the proper extension.

[http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f5-51556.html](http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f5-51556.html)

there are a number of dylib files with gtk in it:

/private/opt/local/lib anne$ ls libgtk\*  
libgtk-1.2.0.9.1.dylib libgtkglext-x11-1.0.0.2.4.dylib  
libgtk-1.2.0.dylib libgtkglext-x11-1.0.0.dylib  
libgtk-x11-2.0.0.800.16.dylib libgtkglext-x11-1.0.a  
libgtk-x11-2.0.0.dylib libgtkglext-x11-1.0.dylib  
libgtk-x11-2.0.dylib libgtkglext-x11-1.0.la  
libgtk-x11-2.0.la libgtkhtml-2.0.0.0.dylib  
libgtk.1.dylib libgtkhtml-2.0.dylib  
libgtk.a libgtkhtml-2.a  
libgtk.dylib libgtkhtml-2.dylib  
libgtk.la libgtkhtml-2.la

I tried recompiling by hand, starting with gettext glib, etc. I  
download the gettext source, and the configure, make of gettext gave an  
error, so I posted my problem to the ruby gettext list in case that is  
part of my trouble.

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [July 30, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/gdk-create-cairo-context-not-found/100247/13 "2006-07-30T17:42:34Z")

</div>

Victory!!!

Thank you so much for explaining to me that ruby-gettext has nothing to  
do with gettext, ruby-gnome2 has nothing to do with gnome2. That set my  
mind free to only worry about my ruby installation.

I uninstalled ruby, and all other darwin ports, reinstalled them,  
reinstalled rubygems, installed the gettext gem, installed the gtk  
files one by one, making sure the dependencies were ok.

and this little program works! Amazing.
