我是 go lang 开发的初学者,我尝试从 go 服务器连接云 oracle 数据库(使用 'github.com/godror/godror' 包)。我安装了 Oracle 即时客户端并设置了环境路径。Go 服务器正在运行并且能够建立连接和查询。但是当我构建一个生产应用程序时出现了这些错误。命令:env GOOS=linux GOARCH=amd64 go build -o odb db_main.go../github.com/godror/godror/orahlp.go:452:53: undefined: VersionInfo../github.com/godror/godror/orahlp.go:461:53: undefined: VersionInfo../github.com/godror/godror/orahlp.go:479:19: undefined: VersionInfo../github.com/godror/godror/orahlp.go:480:19: undefined: VersionInfo../github.com/godror/godror/orahlp.go:481:30: undefined: ObjectType../github.com/godror/godror/orahlp.go:482:31: undefined: Event../github.com/godror/godror/orahlp.go:482:42: undefined: SubscriptionOption../github.com/godror/godror/orahlp.go:482:64: undefined: Subscription../github.com/godror/godror/orahlp.go:483:10: undefined: StartupMode../github.com/godror/godror/orahlp.go:484:11: undefined: ShutdownMode../github.com/godror/godror/orahlp.go:484:11: too many errors```My server code(db_main.go)```package mainimport ( "database/sql" "encoding/json" "fmt" "log" "net/http" "time"_ "github.com/godror/godror")// VersionInfo,ObjectType,Event,SubscriptionOption,Subscription,StartupMode,ShutdownModevar db *sql.DBfunc main() { var err error db, err = sql.Open("godror", "xyz/abc@13.43.11.8:1521/sampledb") if err != nil { log.Println("Error") fmt.Println(err) return } defer db.Close() port := ":8000" http.HandleFunc("/insert", InsertData) http.HandleFunc("/list", GetList) log.Println("Tranzo-Shahi Oracle DB running in ", port) httpErr := http.ListenAndServe(port, nil) if httpErr != nil { log.Println("Tranzo-Shahi Oracle DB Error: ", httpErr.Error()) }}
2 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
不幸的是,原始问题没有提到构建运行的位置。知道这一点很重要。
当您尝试交叉编译代码时,godror文档指出了可能出现的问题。在他们的文档中:Cgo is required, so cross-compilation is hard, and you cannot set CGO_ENABLED=0!
我建议在 Linux 机器上运行你的构建。(验证它是否安装了gcc。)
运行您的构建env CGO_ENABLED=1 go build -o odb
萧十郎
TA贡献1815条经验 获得超12个赞
运行env GOOS=linux GOARCH=amd64 go build -o odb
并且不指定任何文件。如果您确实指定了一个,db_main.go
那么您需要指定必须包含在构建中的包中的所有文件。
- 2 回答
- 0 关注
- 278 浏览
添加回答
举报
0/150
提交
取消