背景
需要在mac机上编译出linux使用的应用,引用了go-sqlite3包,出现编译错误
错误详情
qiantao@qiant elfishfs-go % CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-linkmode external -extldflags -static" -o demo
# github.com/mattn/go-sqlite3
sqlite3-binding.c:33886:42: error: use of undeclared identifier 'pread64'
sqlite3-binding.c:33904:42: error: use of undeclared identifier 'pwrite64'
sqlite3-binding.c:34037:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:34046:22: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:34073:20: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:34090:16: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14567:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:34094:14: error: invalid application of 'sizeof' to an incomplete type 'struct unix_syscall []'
sqlite3-binding.c:14567:38: note: expanded from macro 'ArraySize'
sqlite3-binding.c:36748:11: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33890:49: note: expanded from macro 'osPread64'
sqlite3-binding.c:36860:17: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sqlite3-binding.c:33908:57: note: expanded from macro 'osPwrite64'
问题
需要交叉工具编译
解决
安装交叉编译工具
brew install FiloSottile/musl-cross/musl-cross
重新编译
CC=x86_64-linux-musl-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-linkmode external -extldflags -static" -o demo
参考资源
有疑问加站长微信联系(非本文作者)