Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

static build problems #62

Closed
airedwin opened this issue Jan 28, 2020 · 12 comments
Closed

static build problems #62

airedwin opened this issue Jan 28, 2020 · 12 comments

Comments

@airedwin
Copy link

When building with
CGO_ENABLED=0

I'm getting

vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:40:30: undefined: clib.XMLXPathObjectType
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:45:9: undefined: clib.XMLXPathObjectFloat64
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:50:9: undefined: clib.XMLXPathObjectBool
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:74:13: undefined: clib.XMLXPathObjectNodeList
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:91:13: undefined: clib.XMLXPathObjectNodeList
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:124:2: undefined: clib.XMLXPathFreeObject
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:129:14: undefined: clib.XMLXPathCompile
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:149:2: undefined: clib.XMLXPathFreeCompExpr
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:163:17: undefined: clib.XMLXPathNewContext
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:179:9: undefined: clib.XMLXPathContextSetContextNode
vendor/github.com/lestrrat-go/libxml2/xpath/xpath.go:179:9: too many errors

github.com/18F/e-QIP-prototype/api/vendor/github.com/lestrrat-go/libxml2/xsd

vendor/github.com/lestrrat-go/libxml2/xsd/xsd.go:29:15: undefined: clib.XMLSchemaParse
vendor/github.com/lestrrat-go/libxml2/xsd/xsd.go:40:15: undefined: clib.XMLSchemaParseFromFile
vendor/github.com/lestrrat-go/libxml2/xsd/xsd.go:55:12: undefined: clib.XMLSchemaFree
vendor/github.com/lestrrat-go/libxml2/xsd/xsd.go:65:10: undefined: clib.XMLSchemaValidateDocument

@lestrrat
Copy link
Collaborator

lestrrat commented Jan 29, 2020

This is a binding to libxml2, which requires cgo so CGO_ENABLED=0 does not make sense.

@airedwin
Copy link
Author

airedwin commented Jan 29, 2020

This is a binding to libxml2, which requires cgo so CGO_ENABLED=0 does not make sense.

you are right, I thought I edited this post, I get errors when trying to make a static build with
go build -ldflags '-w -extldflags "-static"'

@lestrrat
Copy link
Collaborator

Without thinking I just copied your command: go build -w -ldflags '-extldflags "-static"' and got

go build -w -ldflags '-extldflags "-static"'
flag provided but not defined: -w
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.

I understand that the above could just be a typo and what not, but just to make sure, can you kindly reproduce this again and paste the actual go command invocation plus the associated logs (doesn't need to be the entire log, just a few lines is fine)?

@airedwin
Copy link
Author

Without thinking I just copied your command: go build -w -ldflags '-extldflags "-static"' and got
go build -w -ldflags '-extldflags "-static"'
flag provided but not defined: -w
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.

I understand that the above could just be a typo and what not, but just to make sure, can you kindly reproduce this again and paste the actual go command invocation plus the associated logs (doesn't need to be the entire log, just a few lines is fine)?

thanks for the help, here is the log, works fine when building without static, but I believe we had it configured to try to build static when deployed in docker

go build -ldflags '-w -extldflags "-static"' -o ./bin/app ./cmd/app

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-354092682/000021.o: In function mygetgrouplist': /workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /tmp/go-link-354092682/000020.o: In function mygetgrgid_r':
/workdir/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-354092682/000020.o: In function mygetgrnam_r': /workdir/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-354092682/000020.o: In function mygetpwnam_r':
/workdir/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-354092682/000020.o: In function mygetpwuid_r': /workdir/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-354092682/000004.o: In function _cgo_7e1b3c2abc8d_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:57: 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/6/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0x9ca): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

@lestrrat
Copy link
Collaborator

lestrrat commented Jan 29, 2020

I have a feeling it's because of this golang/go#26492

Seems like the full solution hasn't landed yet, and for now it will probably be easier if you just edit (possibly via a custom build script that gets invoked when you build your tool) the file clib/clib.go and change

#cgo pkg-config: libxml-2.0

to

#cgo pkg-config: --static libxml-2.0

@lestrrat lestrrat changed the title build problems static build problems Jan 29, 2020
@airedwin
Copy link
Author

I have a feeling it's because of this golang/go#26492
Seems like the full solution hasn't landed yet, and for now it will probably be easier if you just edit (possibly via a custom build script that gets invoked when you build your tool) the file clib/clib.go and change
#cgo pkg-config: libxml-2.0

to
#cgo pkg-config: --static libxml-2.0

thanks, I saw that issue as well, wasn't sure if it was related
i'm doing normal builds for now but i'm not sure if that will affect anything, so far it's fine
we run dep ensure in our deployments so i'm not certain I can modify clib.go without it getting changed back, is there something I need to configure... maybe the lockfile?

@lestrrat
Copy link
Collaborator

If I were you I'd just bite the bullet and run dep ensure then modify the file inplace using sed or perl, then build. I know, not an ideal solution but it should work

@leonged
Copy link

leonged commented Jan 31, 2020

not sure if that worked

$ mv clib.go.custom /go/src/github.com/myapp/vendor/github.com/lestrrat-go/libxml2/clib/clib.go
$ export GOOS=linux
$ export GOARCH=amd64
$ go build -ldflags '-w -extldflags "-static"' -o ./bin/myapp ./myapp

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-736995541/000021.o: In function mygetgrouplist': /workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /tmp/go-link-736995541/000020.o: In function mygetgrgid_r':
/workdir/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-736995541/000020.o: In function mygetgrnam_r': /workdir/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-736995541/000020.o: In function mygetpwnam_r':
/workdir/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-736995541/000020.o: In function mygetpwuid_r': /workdir/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-736995541/000004.o: In function _cgo_7e1b3c2abc8d_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:57: 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/6/../../../x86_64-linux-gnu/libxml2.a(nanohttp.o): In function xmlNanoHTTPConnectHost': (.text+0x9ca): 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/6/../../../x86_64-linux-gnu/libicuuc.a(putil.ao): In function uprv_dl_open_63':
(.text+0x1952): undefined reference to dlopen' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(putil.ao): In function uprv_dlsym_func_63':
(.text+0x199d): undefined reference to dlsym' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(putil.ao): In function uprv_dl_close_63':
(.text+0x1981): undefined reference to dlclose' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(uobject.ao): In function icu_63::UMemory::operator new(unsigned long) [clone .cold.0]':
(.text.unlikely+0xc): undefined reference to __cxa_call_unexpected' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(uobject.ao): In function icu_63::UMemory::operator delete(void*) [clone .cold.1]':
(.text.unlikely+0x1c): undefined reference to __cxa_call_unexpected' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(uobject.ao):(.data.rel.ro._ZTIN6icu_637UMemoryE[_ZTIN6icu_637UMemoryE]+0x0): undefined reference to vtable for __cxxabiv1::__class_type_info'
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(uobject.ao):(.data.rel.ro._ZTIN6icu_637UObjectE[_ZTIN6icu_637UObjectE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info' /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libicuuc.a(ucln_cmn.ao):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to __gxx_personality_v0'

@lestrrat
Copy link
Collaborator

lestrrat commented Feb 2, 2020

There are two problems that you can see in the logs: os/user, and libicu. The os/user problem seems to be referenced from the same issue golang/go#26492, and seems to stem from probably the same cause, and you probably need to use the incantation referenced in the original post on that same issue (or, stop using os/user).

For libicu, I'm not sure, but it's something from libxml2 -- I don't get that in my environment :/

@lestrrat
Copy link
Collaborator

lestrrat commented Feb 15, 2020

I referenced this in the README. I believe there's little I can do at this point from libxml2 binding's side to help you guys, so I'm going to close this for now. Feel free to reopen it if you believe that I'm doing something wrong and that I can make things a bit easier for you. Thanks.

@andreymazuro
Copy link

@leonged did you manage to solve this issue?

@airedwin
Copy link
Author

@leonged did you manage to solve this issue?

I don't remember what I did. I think I just scrapped it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants