我正在尝试使用以下代码在 Go 中使用 XLib:
package main
// #cgo LDFLAGS: -lX11
// #include <X11/Xlib.h>
import (
"C"
"fmt"
)
func main() {
var dpy = C.XOpenDisplay(nil);
if dpy == nil {
panic("Can't open display")
}
fmt.Println("%ix%i", C.XDisplayWidth(), C.XDisplayHeight());
}
我正在通过以下方式编译它:
go tool cgo $(FILE)
但它会导致以下错误消息:
1: error: 'XOpenDisplay' undeclared (first use in this function)
1: note: each undeclared identifier is reported only once for each function it appears in
1: error: 'XDisplayWidth' undeclared (first use in this function)
1: error: 'XDisplayHeight' undeclared (first use in this function)
知道如何解决这个问题吗?