'未定义参考'编写开罗计划 - 尽管尝试解决类似的问题

时间:2017-04-10 18:23:58

标签: c compilation cairo

注意:此问题与thisthis不重复 - 这些解决方案 不适用于我。

我正在尝试使用Cairo编译程序。我直接从the Cairo FAQ复制了我的代码:

#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;
}

我已安装libcairo2-dev(XUbuntu 16.04。)Cairo位于/usr/lib/x86_64-linux-gnu。我编写了一个makefile,它使用pkg-config来识别正确的库:

CC=cc
CFLAGS=$(shell pkg-config --cflags cairo)
LFLAGS=-L/usr/lib/x86_64-linux-gnu $(shell pkg-config --libs cairo)

OBJECTS=main.o
BIN=main

$(BIN): $(OBJECTS)
    $(CC) $(LFLAGS) $(OBJECTS) -o $(BIN)

%.o: %.c
    gcc -c $(CFLAGS) $< -o $@

clean:
    rm -rf *.o

然而,当我运行make时:

cc -L/usr/lib/x86_64-linux-gnu -lcairo main.o -o main
main.o: In function `main':
main.c:(.text+0x1f): undefined reference to `cairo_image_surface_create'
main.c:(.text+0x2f): undefined reference to `cairo_create'
main.c:(.text+0x4e): undefined reference to `cairo_select_font_face'
main.c:(.text+0x6d): undefined reference to `cairo_set_font_size'
main.c:(.text+0x89): undefined reference to `cairo_set_source_rgb'
main.c:(.text+0xb4): undefined reference to `cairo_move_to'
main.c:(.text+0xc5): undefined reference to `cairo_show_text'
main.c:(.text+0xd1): undefined reference to `cairo_destroy'
main.c:(.text+0xe2): undefined reference to `cairo_surface_write_to_png'
main.c:(.text+0xee): undefined reference to `cairo_surface_destroy'
collect2: error: ld returned 1 exit status
Makefile:9: recipe for target 'main' failed
make: *** [main] Error 1

0 个答案:

没有答案