我开始学习C的cairo,我以前安装了cairo库(libcairo2-dev),我在/ usr / include中有文件夹cairo。 我试图以各种方式编译它(也使用pkg-config --cflags --libs cairo)和静态链接,但没有:
#include <cairo/cairo.h>
int main(void)
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 390, 60);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 50.0);
cairo_move_to(cr, 10.0, 50.0);
cairo_show_text(cr, "Hi at all");
cairo_surface_write_to_png(surface, "image.png");
cairo_destroy(cr);
cairo_surface_destroy(surface);
return 0;
}
编译错误是:
cairo.c:(.text+0x1e): undefined reference to `cairo_image_surface_create'
cairo.c:(.text+0x2f): undefined reference to `cairo_create'
cairo.c:(.text+0x5b): undefined reference to `cairo_set_source_rgb'
cairo.c:(.text+0x6f): undefined reference to `cairo_select_font_face'
cairo.c:(.text+0x8a): undefined reference to `cairo_set_font_size'
cairo.c:(.text+0xb2): undefined reference to `cairo_move_to'
cairo.c:(.text+0xc5): undefined reference to `cairo_show_text'
cairo.c:(.text+0xd8): undefined reference to `cairo_surface_write_to_png'
cairo.c:(.text+0xe6): undefined reference to `cairo_destroy'
cairo.c:(.text+0xf4): undefined reference to `cairo_surface_destroy'
collect2: error: ld returned 1 exit status
我该如何解决这个问题?