Этот вопрос аналогичен go -sqlite3 аргументам компилятора для кросс-компиляции OSX до linux, но, поскольку на этот вопрос нет ответа, я попытаюсь задать его снова. У меня есть пакет Go, в котором используется драйвер github.com / mattn / go -sqlite3 SQLite3, аналогичный следующему:
package main
import (
_ "github.com/mattn/go-sqlite3"
)
Однако, если я пытаюсь скомпилируйте это для Linux AMD64 с включенной CGO (как того требует SQLite3), я получаю следующие ошибки:
> env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build
# github.com/mattn/go-sqlite3
sqlite3-binding.c:33123:42: error: use of undeclared identifier 'pread64'
sqlite3-binding.c:33141:42: error: use of undeclared identifier 'pwrite64'
sqlite3-binding.c:33274:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33283:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33310:20: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:33327:16: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14220:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:33331:14: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14220:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:35984:11: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33127:49: note: expanded from macro 'osPread64'
sqlite3-binding.c:36096:17: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33145:57: note: expanded from macro 'osPwrite64'
Аналогично, если я укажу --tags "linux"
, как описано в https://github.com/mattn/go-sqlite3#linux, я получаю следующие ошибки:
> go build --tags "linux"
# runtime/internal/sys
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:8:7: GOOS redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:7:14
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:10:7: GoosAix redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:9:17
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:11:7: GoosAndroid redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:10:21
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:12:7: GoosDarwin redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:11:20
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:13:7: GoosDragonfly redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:12:23
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:14:7: GoosFreebsd redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:13:21
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:15:7: GoosHurd redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:14:18
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:16:7: GoosJs redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:15:16
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:17:7: GoosLinux redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:16:19
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:18:7: GoosNacl redeclared in this block
previous declaration at /usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_darwin.go:17:18
/usr/local/Cellar/go@1.12/1.12.12/libexec/src/runtime/internal/sys/zgoos_linux.go:18:7: too many errors
# runtime/cgo
duplicate symbol '__cgo_sys_thread_start' in:
$WORK/b040/_x004.o
$WORK/b040/_x007.o
duplicate symbol '_x_cgo_init' in:
$WORK/b040/_x004.o
$WORK/b040/_x007.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Как я могу кросс-компилировать этот пакет на моем ноутбуке MacOS (Darwin AMD64) для запуска на облачной Google Linux VM?