Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation/Linking to Cairo Library

I am trying to test out a few simple Cairo programs, but I am having trouble figuring how to include the source files. I have installed the Cairo library - it's just a question of how to let gcc know...

  • I have the .h files (including cairo.h) installed in /usr/local/include/cairo
  • I have the .dylib files installed in /usr/local/lib and /usr/local/lib/cairo

Are there any other components of the installation I should be aware of? (I just did 'make install' to install the library)

I am trying to compile like this:

$ gcc cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/

My cairoTest.c file starts out with:

include <cairo.h>

gcc is finding cairo.h, but it gives the following error message. I think it is not linking to the .dylib files correctly, but I'm not sure. I'm still new to compiling/linking.

gcc cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/cairo
Undefined symbols for architecture x86_64:
  "_cairo_image_surface_create", referenced from:
      _main in ccVd9Pet.o
  "_cairo_create", referenced from:
      _main in ccVd9Pet.o
  "_cairo_scale", referenced from:
      _main in ccVd9Pet.o
  "_cairo_set_line_width", referenced from:
      _main in ccVd9Pet.o
  "_cairo_set_source_rgb", referenced from:
      _main in ccVd9Pet.o
  "_cairo_rectangle", referenced from:
      _main in ccVd9Pet.o
  "_cairo_stroke", referenced from:
      _main in ccVd9Pet.o
  "_cairo_surface_write_to_png", referenced from:
      _main in ccVd9Pet.o
  "_cairo_destroy", referenced from:
      _main in ccVd9Pet.o
  "_cairo_surface_destroy", referenced from:
      _main in ccVd9Pet.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [all] Error 1

What should I be doing differently to include the Cairo library in my compilation?

Thanks,

like image 769
user1005954 Avatar asked Feb 23 '23 04:02

user1005954


1 Answers

Try to compile with

 gcc -Wall -g cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/ -lcairo -o cairoTest

(but you probably need other libraries, perhaps thru $(pkg-config --cflags --libs cairo) or similar)

And your file should start with

 #include  <cairo.h>
like image 172
Basile Starynkevitch Avatar answered Mar 03 '23 14:03

Basile Starynkevitch