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.

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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?