doubu1950 2013-06-14 09:48
浏览 82
已采纳

使用gco在Go中通过gtk使用glib的问题

My understanding of C is quite poor. I can read the code, but I have no idea how to include/build/make/configure anything. This is probably why I do not manage to get the following Go code to compile. This code my attempt at adapting https://developer.gnome.org/gtk3/3.0/gtk-getting-started.html to Go.

package main

// #cgo pkg-config: gtk+-3.0
// #include <gtk/gtk.h>
import "C"

func main() {
    C.gtk_init(nil, nil)
    window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
    C.g_signal_connect(window, "destroy", C.G_CALLBACK(C.gtk_main_quit), nil)
    C.gtk_widget_show(window)
    C.gtk_main()
}

The offending line is C.g_signal_connect(...). The errors are:

1: error: 'G_CALLBACK' undeclared (first use in this function)
1: error: 'g_signal_connect' undeclared (first use in this function)
1: note: each undeclared identifier is reported only once for each function it appears in

If I remove the line, then the code works and the gtk windows opens.

I figured out that this g_signal_connect comes from glib-object.h, which is included in many header files of gtk. I tried to include it myself:

// #cgo pkg-config: gtk+-3.0 glib-2.0
// #include <gtk/gtk.h>
// #include <glib-object.h>

but it did not solve anything.

Does anybody know what I am doing wrong?

  • 写回答

1条回答 默认 最新

  • dongyan7950 2013-06-14 10:57
    关注

    The functions you're trying to call are probably actually macros, which are not handled by cgo and are therefore undefined. Take a look at go-gtk, which provides proper bindings to GTK for Go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?