duanjuduo4573 2014-04-14 15:59
浏览 104
已采纳

使用SQL驱动程序交叉编译Go程序

I have a very simple working Go test program which uses Oracle SQL driver ("github.com/mattn/go-oci8"). I build and test it on OS X and it works. Now I want to cross-compile and run it on Linux. I compiled it like this:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install github.com/mattn/go-oci8
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build myoracle.go

but when I try to run it, I get

$ ./myoracle
sql: unknown driver "oci8" (forgotten import?)

The code looks like this::

import (
    "database/sql"
    "fmt"
    _ "github.com/mattn/go-oci8"
    "os"
)

func main() {
    os.Setenv("NLS_LANG", "")

    db, err := sql.Open("oci8", "user/pass@dbserver:1521/SVC")
    if err != nil {
        fmt.Println(err)
        return
    }
}
  • 写回答

2条回答 默认 最新

  • dongshen7561 2014-04-14 16:41
    关注

    Most ( / all?) SQL drivers are just wrappers for the actual C library.

    Your only option is to use a virtual machine with the OS you want to compile for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开