Cross compiling failed. · Issue #372 · mattn/go-sqlite3
2021-04-07 23:38:44 Author: github.com(查看原文) 阅读量:197 收藏

@GJRTimmer thank you for taking the time to make the instructions! I also found the 'FiloSottile/musl-cross/musl-cross' and tried it out without success. I get the following error when trying to cross-compile from macOS to linux:

GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CGO_ENABLED=1 go build -a -v -o app
...
golang.org/x/sys/cpu
# runtime/cgo
dyld: Library not loaded: @@HOMEBREW_PREFIX@@/opt/isl/lib/libisl.15.dylib
  Referenced from: /usr/local/Cellar/musl-cross/0.9.7/libexec/bin/../libexec/gcc/x86_64-linux-musl/6.3.0/cc1
  Reason: image not found
x86_64-linux-musl-gcc: internal compiler error: Abort trap: 6 (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

After some research it looks like the problem is the version of the gcc is outdated, I can be way off and this might be obvious to someone else. So if anybody stumbles on this, then please try to see if the x86_64-linux-musl-gcc works for you. I however ended up giving up on the cross-compiler and just compiled it in a docker golang container.
I modified the golang container so that it includes gcc and musl-dev:

...
RUN apk add --no-cache \
		gcc \
		musl-dev \
		ca-certificates
...

then I created the docker image e.g.

docker build -f Dockerfile.golang -t golang:crosscompiler .
docker run --rm -v "$HOME/go/src:/go/src" -w /go/src/$(PROJECT) -e GOOS=linux -e GOARCH=amd64 -e CGO_ENABLED=1 golang:crosscompiler go build -v -ldflags '-w -extldflags "-static"' -o app .

where $(PROJECT) is the path to your project.

Thank you again for the help!


文章来源: https://github.com/mattn/go-sqlite3/issues/372
如有侵权请联系:admin#unsafe.sh