我想用下面的C作爲Go的CGO:去+ CGO和鏈接
#include <X11/extensions/scrnsaver.h>
main() {
XScreenSaverInfo *info = XScreenSaverAllocInfo();
Display *display = XOpenDisplay(0);
XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
printf("%u ms\n", info->idle);
}
構建具有:
gcc -o idle printXIdleTime.c -lX11 -lXss
我重新寫了Go的CGO代碼:
package tools
// #cgo pkg-config: x11
// #include <X11/extensions/scrnsaver.h>
import "C"
func GetIdleTime() (idleTime uint32) {
var info *C.XScreenSaverInfo
var display *C.Display
info = C.XScreenSaverAllocInfo()
display = C.XOpenDisplay(0)
defaultRootWindow := C.XDefaultRootWindow(display)
C.XScreenSaverQueryInfo(display, defaultRootWindow, info)
idleTime = info.idle
return
}
試圖編譯:
go build -gccgoflags="-lXss -lX11"
但是我得到的鏈接錯誤:
/tmp/go-build076004816/opensource.stdk/lib/tools/_obj/x11.cgo2.o: In function
_cgo_c0e279f6f16e_Cfunc_XScreenSaverAllocInfo': ./x11.go:52: undefined reference to
XScreenSaverAllocInfo' /tmp/go-build076004816/opensource.stdk/lib/tools/_obj/x11.cgo2.o: In function_cgo_c0e279f6f16e_Cfunc_XScreenSaverQueryInfo': ./x11.go:65: undefined reference to
XScreenSaverQueryInfo' collect2: error: ld returned 1 exit status
我到底做錯了什麼?
與GOS XGB的問題是,如果我沒有我的家中的.XAuthority NewConn()失敗並顯示消息「無法連接」 – 2013-02-13 20:01:22
XGB應該發出警告消息,但無論如何連接。你能否提交一份包含測試用例和環境描述的錯誤報告? https://github.com/BurntSushi/xgb/issues – BurntSushi5 2013-02-14 00:28:03