【问题标题】:How to compile program with gtk+-3.0?如何用gtk+-3.0编译程序?
【发布时间】:2015-08-07 08:40:13
【问题描述】:

我在 ubuntu 12.04 中使用 GTK+-3.0。我正在尝试编译程序但每次都失败

apple@ubuntu:~/Downloads$ gcc -Wall -g gtktest.c $(pkg-config --libs --cflags gtk+-3.0) -o gtktest

gtktest.c: In function ‘main’:
gtktest.c:21:3: warning: implicit declaration of function ‘gtk_signal_connect’ [-Wimplicit-function-declaration]
gtktest.c:21:3: warning: implicit declaration of function ‘GTK_OBJECT’ [-Wimplicit-function-declaration]
gtktest.c:21:3: warning: implicit declaration of function ‘GTK_SIGNAL_FUNC’ [-Wimplicit-function-declaration]
gtktest.c:22:3: warning: implicit declaration of function ‘gtk_container_border_width’ [-Wimplicit-function-declaration]
gtktest.c:28:3: warning: implicit declaration of function ‘gtk_signal_connect_object’ [-Wimplicit-function-declaration]
/tmp/ccH48jvQ.o: In function `main':
/home/apple/Downloads/gtktest.c:21: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:21: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:21: undefined reference to `gtk_signal_connect'
/home/apple/Downloads/gtktest.c:22: undefined reference to `gtk_container_border_width'
/home/apple/Downloads/gtktest.c:26: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:26: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:26: undefined reference to `gtk_signal_connect'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:28: undefined reference to `gtk_signal_connect_object'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_lookup'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_insert'
/usr/local/lib/libcairo.so: undefined reference to `pixman_composite_glyphs'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_remove'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_get_mask_format'
/usr/local/lib/libcairo.so: undefined reference to `pixman_composite_glyphs_no_mask'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_thaw'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_freeze'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_create'
collect2: ld returned 1 exit status

使用另一个命令。

apple@ubuntu:~/Downloads$ gcc -Wall -g gtktest.c $(pkg-config --libs --cflags glib-2.0) -o gtktest
        In file included from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:30:0,
                         from /usr/include/gtk-3.0/gdk/gdk.h:32,
                         from /usr/local/include/gtk-3.0/gtk/gtk.h:32,
                         from gtktest.c:1:
        /usr/include/gtk-3.0/gdk/gdktypes.h:37:19: fatal error: cairo.h: No such file or directory
        compilation terminated.

任何人如何解决这个问题我正在尝试解决这个问题过去 4 天。请问有人可以给我正确的解决方案吗?

【问题讨论】:

  • 您似乎缺少 .h 和库?

标签: c ubuntu gtk3 glib


【解决方案1】:
gtktest.c:21:3: warning: implicit declaration of function ‘gtk_signal_connect’

您正在编译的代码是为非常旧的 GTK+ 版本编写的。如果你想用 GTK+3 编译,更不用说工作,你将不得不修改代码。用 GTK+2 编译几乎肯定会更容易开始。

/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_lookup'

我猜你的 cairo 版本需要一个比你链接的更新的 pixman:例如在 pixman 0.27.2 中添加了pixman_glyph_cache_lookup()

最后一个示例尝试在没有 GTK 包含标志的情况下编译 GTK 代码:这是行不通的。

【讨论】:

    【解决方案2】:

    使用

    -lcairo 或 $(pkg-config --libs --cflags cairo)

    和 -lpixman 或 -lpixman-1

    【讨论】:

    • cairo 链接标志已由 pkg-config 使用pkg-config --libs gtk+-3.0 添加,因此没有意义
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2011-05-16
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多