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

huangapple go评论67阅读模式
英文:

cross-compiling Go program with an SQL driver

问题

我有一个非常简单的工作中的Go测试程序,它使用Oracle SQL驱动程序("github.com/mattn/go-oci8")。我在OS X上构建和测试它,它可以正常工作。
现在我想交叉编译并在Linux上运行它。
我像这样编译它:

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

但是当我尝试运行它时,我得到了以下错误:

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

代码如下:

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
}

}

英文:

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
	}
}

答案1

得分: 1

大多数(/全部?)SQL驱动程序只是实际C库的包装器。

您唯一的选择是使用具有您想要编译的操作系统的虚拟机。

英文:

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.

答案2

得分: 0

哦,等等,这是因为github.com/mattn/go-oci8实际上需要CGo,无法进行交叉编译吗?

英文:

Oh, wait, is this because github.com/mattn/go-oci8 actually requires CGo and can't be cross-compiled?

huangapple
  • 本文由 发表于 2014年4月14日 23:59:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/23064752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定