解決

install

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

build

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

Cross compiling failed. · Issue #372 · mattn/go-sqlite3

原因

mattn/go-sqlite3 を含めbuildしたが特にエラーはなく。 しかし実行すると下記の一文が。

Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub

buildするときに、 CGO_ENABLED=1 を加えてみると。

$ env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build
# github.com/user/hoge/vendor/github.com/mattn/go-sqlite3
sqlite3-binding.c:33723:42: error: use of undeclared identifier 'pread64'
sqlite3-binding.c:33741:42: error: use of undeclared identifier 'pwrite64'
sqlite3-binding.c:33874:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33883:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33910:20: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33927:16: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14469:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:33931:14: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14469:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:36584:11: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33727:49: note: expanded from macro 'osPread64'
sqlite3-binding.c:36696:17: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33745:57: note: expanded from macro 'osPwrite64'

Note

brew install go にオプションで、 --with-cc-all--with-cc-common してもオプションが不正となる。

#531 breaks build on Mac OSX · Issue #532 · mattn/go-sqlite3