bash - Golang OpenGL 错误 PlatformError : X11: The DISPLAY environment variable is missing panic: NotInitialized: The GLFW library is not initialized

标签 bash ubuntu go opengl

我似乎无法让 opengl 与 golang 一起工作。我想尝试 golang,但设置起来非常痛苦,现在我无法得到我从 this website 复制粘贴的东西.这是我使用的代码:(from the website) .我在运行它之前执行了这两个命令(在 Windows 上使用 wsl):

go get github.com/go-gl/gl/v4.1-core/gl
go get github.com/go-gl/glfw/v3.2/glfw

这是我得到的完整错误:

2018/11/21 13:43:33 PlatformError: X11: The DISPLAY environment variable is missing
panic: NotInitialized: The GLFW library is not initialized

goroutine 1 [running, locked to thread]:
github.com/go-gl/glfw/v3.2/glfw.acceptError(0x0, 0x0, 0x0, 0x1, 0xc000099ee0)
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:173 +0x1d1
github.com/go-gl/glfw/v3.2/glfw.panicError()
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/error.go:184 +0x32
github.com/go-gl/glfw/v3.2/glfw.WindowHint(0x20003, 0x0)
        /home/oriont/dev/src/github.com/go-gl/glfw/v3.2/glfw/window.go:235 +0x38
main.initGlfw(0x4ded35)
        /home/oriont/dev/super g/main.go:71 +0x54
main.main()
        /home/oriont/dev/super g/main.go:45 +0x2b
exit status 2

如果你好奇,我的 go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oriont/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/oriont/dev"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.11"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.11/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build854283259=/tmp/go-build -gno-record-gcc-switches"

任何帮助将不胜感激,谢谢!

编辑:

在重新安装 go 并删除对 sdl2 的失败尝试(来自 apt-get remove)之后,现在我遇到了一个新错误。

(旧)这是新错误:

# _/home/oriont/dev/super_g
/usr/lib/go-1.11/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lXrandr
collect2: error: ld returned 1 exit status

我仍然拥有所有相同的代码。此外,我确实尝试运行“go build”,但它抛出了与“go run main.go”完全相同的错误。

编辑 2:

我重新安装了 go 1.11.2 并在 sudo apt-get install 上安装了 libglfw3 和 libglfw3-dev 包。现在,我遇到了同样的旧错误。

最佳答案

对于 Alpine Linux,以下方法有效:

  1. 安装以下软件包:apk add --no-cache mesa-dri-swrast glfw-dev mesa-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev
  2. 导出变量 DISPLAY 如下:export DISPLAY=:0
  3. 仅当您使用 Docker 时,安装文件夹 /tmp/.X11-unix(作为源和目标)

关于bash - Golang OpenGL 错误 PlatformError : X11: The DISPLAY environment variable is missing panic: NotInitialized: The GLFW library is not initialized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53420975/

相关文章:

php - 将 POP (Gmail) 电子邮件保存到 MySQL 数据库的最有效方法

ruby - 安装 RVM 后找不到 Ruby 1.9.2

go - 我如何等待接收器 channel 完成它在golang中的执行?

mongodb - 如何在 go(lang) 中连接到 mlab mongodb 数据库?

git - 对于文件路径已满或缩短并依赖于 "token"扩展,创建符号链接(symbolic link)的正确方法是什么

linux - 处理时如何传递+读取参数| (管道)?

python - 如何卸载 setuptools python

ubuntu - 如何在 X11 (Ubuntu) 中设置图标名称

go - 如何在struct Beego中设置unique

linux - 如何在 bash 命令行上指定两个变量?