使用cgo库的应用程序静态golang构建

时间:2018-07-12 11:19:30

标签: go build static-libraries

我决定使用Go wrapper from datadog在代码中使用zstd库进行压缩。
我的应用构建命令是(我使用image: golang:1.10.2-alpine在gitlab-ci中构建我的应用)

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库,然后构建我的应用程序吗?

0 个答案:

没有答案