静态编译时遇到的问题,需要求助

1. 运行环境

go 1.20, linux/amd64,编译ebiten的example

2. 问题描述?

抱歉打扰大家,我请问一个编译时出现的问题,我在编译一个github上的库,使用go build -tags=example github.com/hajimehoshi/ebiten/v2/examples/rotate编译时成功,运行也正常,但是这个编译出的执行程序依赖系统中的很多库,于是我想全静态编译,这样就可以在其他系统上比较方便地部署,于是我使用了CGO_ENABLED=0 go build -tags=example github.com/hajimehoshi/ebiten/v2/examples/rotate,结果出现了一些错误,如:
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/glfw_notwindows.go:26:24: undefined: glfw.Window
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/glfw_notwindows.go:61:10: undefined: glfw.Cursor
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/glfw_notwindows.go:70:10: undefined: glfw.Monitor
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/glfw_notwindows.go:98:10: undefined: glfw.Window
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:24:33: undefined: glfw.CharModsCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:25:33: undefined: glfw.CloseCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:26:33: undefined: glfw.DropCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:27:33: undefined: glfw.FramebufferSizeCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:28:33: undefined: glfw.MonitorCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:30:33: undefined: glfw.SizeCallback
../../go-workspace/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.5.4/internal/glfw/type_notwindows.go:28:33: too many errors
在网上搜索之后我又用了命令go build -ldflags ‘-linkmode “external” -extldflags “-static”‘ -tags=example github.com/hajimehoshi/ebiten/v2/examples/rotate来编译,出现错误如下:

github.com/hajimehoshi/ebiten/v2/examples/rotate

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: 找不到 -lGL
/tmp/go-link-1787075959/000002.o:在函数‘_glfwInitVulkan’中:
/home/smart/go-workspace/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20221017161538-93cebf72946b/glfw/src/vulkan.c:65: 警告:Using ‘dlopen’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-1787075959/000022.o:在函数‘_cgo_cbcce81e6342_C2func_getaddrinfo’中:
/tmp/go-build/cgo-gcc-prolog:58: 警告:Using ‘getaddrinfo’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

再后来又搜索之后听别人说可以使用musl代替c库,又使用了命令:go build -ldflags “-linkmode external -extldflags ‘-static’” -tags musl -tags=example github.com/hajimehoshi/ebiten/v2/examples/rotate,得到结果和上一次命令一样,
有谁能够指点我一下应该怎么处理这个问题,谢谢!

3. 您期望得到的结果?

能够编译出静态链接的程序,运行时不依赖外部动态库
//: <> (能截图就截图。)

4. 您实际得到的结果?

编译时出现了上述错误,目前不知道怎么办
//: <> (有报错信息的话把堆栈信息提供出来)

讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!