I have recently downloaded and installed Cairo graphics library for C from the project website.
I tried to run the hello world program of Cairo by using the given code from the site FAQ. In Terminal, I applied the same command as given by the same page to compile it. But when I tried to compile it, errors of undefined references appeared.
In the Terminal, the output is:
cc -o hello $(pkg-config --cflags --libs cairo) hello.c
/tmp/cco08jEN.o: In function `main':
hello.c:(.text+0x1f): undefined reference to `cairo_image_surface_create'
hello.c:(.text+0x2f): undefined reference to `cairo_create'
hello.c:(.text+0x4e): undefined reference to `cairo_select_font_face'
hello.c:(.text+0x6d): undefined reference to `cairo_set_font_size'
hello.c:(.text+0x89): undefined reference to `cairo_set_source_rgb'
hello.c:(.text+0xbb): undefined reference to `cairo_move_to'
hello.c:(.text+0xcc): undefined reference to `cairo_show_text'
hello.c:(.text+0xd8): undefined reference to `cairo_destroy'
hello.c:(.text+0xe9): undefined reference to `cairo_surface_write_to_png'
hello.c:(.text+0xf5): undefined reference to `cairo_surface_destroy'
collect2: error: ld returned 1 exit status
And my source code is:
#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;
}
as described from the site FAQ.
I am a beginner in using Terminal commands, and Cairo is the first third party library I used for graphics. I tried to find any fix from the Internet, but I didn't get any clue nor fix.
Please tell me my error, and explain to me how to use the libraries.
cairo_create
, fromcairo_image_surface_create
. It does not get as far as linking: the compiler cannot find the header file<cairo.h>
. You have to set up the paths to headers and library somewhere. – Isreal