Compilation / link to the Cairo library

I'm trying to check out some simple Cairo programs, but it's hard for me to figure out how to include the source files. I installed the Cairo library - it's just a question of how to tell gcc ...

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

Are there any other installation components I should be aware of? (I just did "install 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 with:

 include <cairo.h> 

gcc finds cairo.h, but it gives the following error message. I think this is incorrectly associated with .dylib files, but I'm not sure. I'm still new to compilation / 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 do differently to include the Cairo library in my compilation?

Thanks,

+4
source share
1 answer

Try compiling 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 via $(pkg-config --cflags --libs cairo) or similar)

And your file should start with

  #include <cairo.h> 
+6
source

Source: https://habr.com/ru/post/1385205/


All Articles