登录
首页 >  Golang >  Go问答

在 Alpine Docker 容器的 Go 编译时遇到“loadinternal:cgo runtime not found”错误

来源:stackoverflow

时间:2024-03-28 22:57:30 436浏览 收藏

珍惜时间,勤奋学习!今天给大家带来《在 Alpine Docker 容器的 Go 编译时遇到“loadinternal:cgo runtime not found”错误》,正文内容主要涉及到等等,如果你正在学习Golang,或者是对Golang有疑问,欢迎大家关注我!后面我会持续更新相关内容的,希望都能帮到正在学习的大家!

问题内容

我正在尝试为启用 fips 的 go 版本构建 alpine docker 映像。为此,我尝试使用 golang/go 存储库的 dev.boringcrypto 分支从源代码构建 go。

运行 ./all.bash 时,出现以下错误:

Step 4/4 : RUN cd go/src && ./all.bash
 ---> Running in 00db552598f7
Building Go cmd/dist using /usr/lib/go.
# _/go/src/cmd/dist
loadinternal: cannot find runtime/cgo
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64- 
alpine-linux-musl/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64- 
alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared
collect2: error: ld returned 1 exit status

The command '/bin/bash -c cd go/src && ./all.bash' returned a non-zero code: 2

这会导致安装测试失败并将我踢出 docker 映像构建。

我在映像上安装了 gcc,并尝试按照其他问题中的建议设置环境变量 cgo_enabled=0,但这些似乎都无法缓解问题。

我对这个问题束手无策。过去有其他人遇到过类似的问题吗?我不明白为什么会发生这种情况,因为构建在 ubuntu 容器中运行良好。

谢谢!


解决方案


尽管我正在编译不同的项目,但我遇到了相同的错误消息。

事实证明,alpine 需要安装 musl-dev 软件包才能正常工作,所以我认为您需要确保它包含在您的 Dockerfile 中,或者通过运行 apk add --no-cache 手动安装它musl-dev

今天关于《在 Alpine Docker 容器的 Go 编译时遇到“loadinternal:cgo runtime not found”错误》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>