top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Help with programming using libcairo

0 votes
226 views

Im trying to work with the tutorial at http://cairographics.org/tutorial/ but cannot get anything to compile and link. I entered their first example, and all of the cairo_* symbols show up undefined in the link phase.

I am compiling the tutorials simplest example, a hello.c program, using

gcc `pkg-config --cflags --libs cairo`Â  -static hello.c -o hello

and it looks like the librarys empty. However, when I use nm(1) on /usr/lib/i386-linux-gnu/cairo.so
I see those symbols. The nm utility does not seem to work on the .so library, even after following symlinks.

pkg-config --libs cairo
just emits "-lcairo"

Ive tried inserting -L /usr/lib/i36-linux-gnu/ to no avail.

I am not sure what else to try.

posted May 16, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Can you post your example program somewhere?

2 Answers

0 votes
#include 

int main (int argc, char *argv[])
{
  cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
  cairo_t *cr =  cairo_create (surface);

  cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  cairo_set_font_size (cr, 32.0);
  cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
  cairo_move_to (cr, 10.0, 50.0);
  cairo_show_text (cr, "Hello, world");

  cairo_destroy (cr);
  cairo_surface_write_to_png (surface, "hello.png");
  cairo_surface_destroy (surface);
  return 0;
}

It compiles okay to a .o file. I cant figure out how to link it. If it matters, Im running Xubuntu 12.04, with all the relevant development packages.

answer May 17, 2013 by anonymous
0 votes

Sorry for delay in replying. Answer is simple. Put the name of the source file before the pkg-config bit opf your command, i.e.,

gcc hello.c `pkg-config --cflags --libs cairo-png` -o hello

I also changed '--libs cairo' to '--libs cairo-png'. Not sure if that is really needed. Also remove the -static option.

answer May 19, 2013 by anonymous
...