Cross compilation fails
rolandjitsu opened this issue · 5 comments
As reported in vmihailenco/taskq#55, if I try to cross compile a project that has a indirect dependency on this package I get:
❯ env GOOS=linux GOARCH=arm CGO_ENABLED=0 go build ./cmd/api/main.go
# github.com/valyala/gozstd
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:31:59: undefined: CDict
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:35:64: undefined: CDict
../../go/pkg/mod/github.com/valyala/gozstd@v1.6.2/stream.go:47:20: undefined: Writer
Try running the following command before building the app:
cd ../../go/pkg/mod/github.com/valyala/gozstd && make clean libzstd.a
This command should re-build libzstd.a
file for the host GOOS and GOARCH as mentioned in the FAQ.
I managed to build it with a C cross compiler:
env CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build ./cmd/api/main.go
But I could only do this on Linux. So I use docker to cross compile on a Mac.
I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.
I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.
My suggestion will work only when building binaries for host system. It doesn't work for cross-compilation :(
I'm not sure if your suggestion would work if I do it on macOS and use the resulted binary on an ARM architecture.
My suggestion will work only when building binaries for host system. It doesn't work for cross-compilation :(
That's ok, it can be done using docker, so that's good enough I'd say. I will close this issue, but maybe it's worth mentioning in the docs that one must use a C cross compiler and the appropriate flags when cross compiling.
maybe it's worth mentioning in the docs that one must use a C cross compiler and the appropriate flags when cross compiling.
Agreed. Could you prepare the corresponding pull request?