Golang交叉编译go-sqlite3

远航
2022-04-20 / 0 评论 / 409 阅读 / 正在检测是否收录...
背景
需要在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

作者:guhan121
链接:https://www.jianshu.com/p/6ec6021c0e46
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

1

评论

博主关闭了当前页面的评论