Golang代码:
package main
import (
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func main() {
application := app.New()
window = application.NewWindow("Hello rohan")
window.SetContent(widget.NewLabel("Hello again"))
window.ShowAndRun()
}
当执行此代码时,我会得到以下错误。
# pkg-config --cflags -- gl gl
Package gl was not found in the pkg-config search path.
Perhaps you should add the directory containing `gl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gl' found
Package gl was not found in the pkg-config search path.
Perhaps you should add the directory containing `gl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gl' found
pkg-config: exit status 1
# fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw
In file included from ./glfw/src/internal.h:188,
from ./glfw/src/context.c:30,
from ../../../go/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw/c_glfw.go:4:
./glfw/src/x11_platform.h:36:10: fatal error: X11/Xcursor/Xcursor.h: No such file or directory
36 | #include <X11/Xcursor/Xcursor.h>
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
如能就这一问题提出任何解决方案或建议,我们将不胜感激。P.S我在windows上使用Go版本1.13.8和ubuntu 20.04 WSL。
在运行sudo apt-get install golang gcc libgl1-mesa-dev xorg-dev
命令后,我现在得到这个错误:
2020/12/21 12:12:19 PlatformError: X11: The DISPLAY environment variable is missing
panic: NotInitialized: The GLFW library is not initialized
goroutine 1 [running, locked to thread]:
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw.acceptError(0x0, 0x0, 0x0, 0x4332bd, 0x991100)
/home/rohan/go/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw/error.go:174 +0x216
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw.panicError(...)
/home/rohan/go/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw/error.go:185
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw.CreateStandardCursor(0x36001, 0x1)
/home/rohan/go/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.3/glfw/input.go:530 +0x4e
fyne.io/fyne/internal/driver/glfw.initCursors()
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/window.go:35 +0x3c
fyne.io/fyne/internal/driver/glfw.(*gLDriver).initGLFW.func1()
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/loop.go:76 +0x6b
sync.(*Once).doSlow(0x10de160, 0xc000068dc8)
/usr/lib/go-1.13/src/sync/once.go:66 +0xe3
sync.(*Once).Do(...)
/usr/lib/go-1.13/src/sync/once.go:57
fyne.io/fyne/internal/driver/glfw.(*gLDriver).initGLFW(0xc0000c00f0)
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/loop.go:69 +0x65
fyne.io/fyne/internal/driver/glfw.(*gLDriver).createWindow.func1()
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/window.go:1175 +0x56
fyne.io/fyne/internal/driver/glfw.runOnMain(0xc0000a5440)
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/loop.go:51 +0xab
fyne.io/fyne/internal/driver/glfw.(*gLDriver).createWindow(0xc0000c00f0, 0x9b7b98, 0xb, 0xc000146001, 0xc000068f08, 0x85c288)
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/window.go:1174 +0xd4
fyne.io/fyne/internal/driver/glfw.(*gLDriver).CreateWindow(0xc0000c00f0, 0x9b7b98, 0xb, 0xc000146000, 0xc0000c00f0)
/home/rohan/go/src/fyne.io/fyne/internal/driver/glfw/window.go:1166 +0x44
fyne.io/fyne/app.(*fyneApp).NewWindow(0xc000146000, 0x9b7b98, 0xb, 0xc000146000, 0x0)
/home/rohan/go/src/fyne.io/fyne/app/app.go:52 +0x47
main.main()
/home/rohan/Code/Go/practice/main.go:10 +0x56
exit status 2
希望有人能在这方面帮助我,或者给我任何关于如何解决它的建议。
一些Linux系统缺少已安装图形库的编译头。值得庆幸的是,这只是开发所需要的——应用程序运行时不会遇到这种情况。
对于Ubuntu或Debian,请尝试sudo apt-get install golang gcc libgl1-mesa-dev xorg-dev
。每个平台的安装各不相同,详细信息请参阅https://developer.fyne.io/started/
我在Linux Mint上遇到了同样的问题,这有助于:
locate pkgconfig/gl.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gl.pc
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig