spacemonkeygo / openssl

OpenSSL bindings for Go
http://godoc.org/github.com/spacemonkeygo/openssl
Apache License 2.0
473 stars 236 forks source link

error during build #115

Closed hbakhtiyor closed 5 years ago

hbakhtiyor commented 5 years ago

getting error while running this command CGO_ENABLED=0 GOOS=linux go build

../../pkg/mod/github.com/spacemonkeygo/openssl@v0.0.0-20181017203307-c2dcc5cca94a/conn.go:30:2: unknown import path "github.com/spacemonkeygo/openssl/utils": cannot find package
../../pkg/mod/github.com/spacemonkeygo/openssl@v0.0.0-20181017203307-c2dcc5cca94a/ctx.go:30:2: unknown import path "github.com/spacemonkeygo/spacelog": cannot find package

go build -a -ldflags '-extldflags "-static"' without env and build static link binary

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-155510809/000004.o: In function `_cgo_18049202ccd9_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:49: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
(.text+0x71): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): undefined reference to `dlopen'
(.text+0x24): undefined reference to `dlsym'
(.text+0x2f): undefined reference to `dlclose'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
(.text+0x1c4): undefined reference to `dlsym'
(.text+0x282): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
(.text+0x2e8): undefined reference to `dlopen'
(.text+0x359): undefined reference to `dlclose'
(.text+0x395): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
(.text+0x461): undefined reference to `dladdr'
(.text+0x4c6): undefined reference to `dlerror'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
(.text+0x6a2): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
zeebo commented 5 years ago

You won't be able to build with CGO_ENABLED=0 as this library is a C wrapper around openssl.

If you want to do a static build, try also adding the -tags openssl_static argument to go build. If you still get a failure, add -x and paste the resulting output.

hbakhtiyor commented 5 years ago

go build -a -ldflags '-extldflags "-static"' -tags openssl_static

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-534046751/000004.o: In function `_cgo_18049202ccd9_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:49: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
(.text+0x71): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

go build -a -x -ldflags '-extldflags "-static"' -tags openssl_static

https://gist.github.com/hbakhtiyor/5bc6f3de247302151bce393dc31e3731

zeebo commented 5 years ago

It looks like you are having problems linking in glibc. Perhaps try statically linking in a different libc. Unfortunately, the details on how to do that are outside of the scope of this project.