英文:
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?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论