Go使用godror库进行交叉编译时,会报以下错误:
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:530:19: undefined: VersionInfo
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:531:19: undefined: VersionInfo
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:532:10: undefined: StartupMode
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:533:11: undefined: ShutdownMode
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:535:31: undefined: Event
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:535:42: undefined: SubscriptionOption
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:535:64: undefined: Subscription
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:536:31: undefined: ObjectType
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:537:59: undefined: Data
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:538:28: undefined: DirectLob
../go/pkg/mod/github.com/godror/godror@v0.34.0/orahlp.go:538:28: too many errors
make: *** [build] Error 2
当程序编译系统和目标系统不一致时会出现以上错误,例如:
- 在windows系统使用go编译linux执行文件
- 在linux系统使用go编译windows执行文件
- 在Mac系统上使用go编译linux执行文件
出现以上错误是因为编译时,交叉编译必须在宿主计算机上安装适当的交叉编译器,该编译器将编译为目标体系结构。官方也提到交叉编译非常困难。官方给出的方案是利用容器进行交叉编译,交叉编译时需设置参数CGO_ENABLED=1
官方交叉编译方案 Godror交叉编译传送门
Comments | NOTHING