go - 使用 cgo 库的应用程序的静态 golang 构建
问题描述
我决定使用 zstd 库在我的代码中使用来自 datadog 的 Go 包装器进行压缩。
我的应用程序构建命令是(我在 gitlab-ci 中使用 构建我的应用程序image: golang:1.10.2-alpine
)
dep ensure --vendor-only
CGO_ENABLE=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' cmd/main.go
哪个失败了
build constraints exclude all Go files in /go/src/xxxxx/xxxx/xxxx/vendor/github.com/DataDog/zstd
当我尝试启用CGO_ENABLED
(并保持其余构建命令不变)时,我最终收到警告:
# command-line-arguments
/tmp/go-link-395607750/000054.o: In function `mygetgrouplist':
/usr/local/go/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-395607750/000053.o: In function `mygetgrgid_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-395607750/000053.o: In function `mygetgrnam_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-395607750/000053.o: In function `mygetpwnam_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-395607750/000053.o: In function `mygetpwuid_r':
/usr/local/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-395607750/000004.o: In function `_cgo_f7895c2c5a3a_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:46: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
这似乎不太好,因为我想让我的构建静态链接。我是否必须首先构建 zstd 库然后构建我的应用程序?
解决方案
推荐阅读
- node.js - 在 Swift 命令行工具中未收到 DistributedNotificationCenter
- javascript - 在 javascritp 上替换一个表
- python - 如何在pyqt5中使背景图片透明?
- python - 在 pandas 中用不同大小的列表列展开多个列
- command-line - grep 命令未显示文件中的所有有效结果
- hybris - 变体和分类之间的区别
- url - URL 中使用什么端口字节顺序?
- java - 如何解决 Exception::java.security.AccessControlException: HttpServlet 中的访问被拒绝
- javascript - Java 正则表达式匹配;第一个小数点前的下划线
- c# - Blazor:每次 for 循环旋转时组件都不会更新