go-sqlite3: Cross compiling failed.

go Version

go version go1.7.4 darwin/amd64

go env

GOARCH="amd64"
GOBIN="/Users/CosPotato/GoProjects/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/CosPotato/GoProjects"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2g/4x1xzstj4vdbj939flg1q7v00000gn/T/go-build152787034=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

what i do

GOOS=linux GOARCH=amd64 ENABLE_CGO=1 go build -o task-server task-server

what i get

github.com/mattn/go-sqlite3
GoProjects/src/github.com/mattn/go-sqlite3/tracecallback_noimpl.go:39: undefined: Error

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 25 (17 by maintainers)

Most upvoted comments

@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!

@arnigudj Check out the file .travis-ci.yml when are building for Mac, you can use the brew commands shown in the travis config.

Then look at the logfile of the one of the builds: https://travis-ci.org/mattn/go-sqlite3/builds/391540953 and try to see what it is they are installing.

I’ve done some homework for you. The following will probably work.

Install cross compilers on your Mac.

brew install FiloSottile/musl-cross/musl-cross  
brew install mingw-w64

For example to cross compile FOR Windows 64Bit FROM you Mac.

Use the following go command

CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 go build -a -v .

Do not forget the -a this will recompile all the go internal packages for the required target.

From this link: https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/

Let us know if you are succesfull with the above, after that you can find a compiler for your desired target and install it with brew and compile what you want.

use gcc instead of clang.

Ok, the latest commit is now working again. Thank you.

Could you please try last commit again?

I’m having these exact same issues. This should compile using go build. Telling people to use other compilation tools isn’t the correct way to solve this.

This package has recently become very unstable. Not sure why, but it seems that the last few weeks there are have been several commits that have broken this project.

please update go-sqlite3