Help with programming using libcairo

Tony Arnold tony.arnold at manchester.ac.uk
Sun May 19 00:29:27 UTC 2013


Kevin,

On 17/05/13 16:15, Kevin O'Gorman wrote:
> On Thu, May 16, 2013 at 2:50 PM, Tony Arnold
> <tony.arnold at manchester.ac.uk <mailto:tony.arnold at manchester.ac.uk>> wrote:
> 
>     Kevin,
> 
>     On 16/05/13 22:35, Kevin O'Gorman wrote:
>     > I'm 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'm compiling the tutorial's simplest example, a hello.c program,
>     using
>     > gcc `pkg-config --cflags --libs cairo`  -static hello.c -o hello
>     >
>     > and it looks like the library's 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"
>     >
>     > I've tried inserting -L /usr/lib/i36-linux-gnu/ to no avail.
>     >
>     > I'm not sure what else to try.
> 
>     Can you post your example program somewhere?
> 
>     Regards,
>     Tony.
> 
> 
> No need for a somewhere, it's so short.  It's from the tutorial
> 
> #include <cairo.h>
> 
> 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 can't figure out how to link it.

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.

HTH.

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 705 344 3082
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list