golang交叉编译:Linux - Windows

环境:
Debian jessie
go 1.7.4
Windows 7

 

背景:

在debian中写好的程序编译后在windows上运行。

程序中使用了sqlite3

import(
  _ "github.com/mattn/go-sqlite3"
)

 

问题:

在debian上使用如下语句编译后,在windows7里运行会提示sqlite3有问题:

CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build

问题如下:

database connection err: sql: unknown driver "sqlite3" (forgotten import?)

 

办法:

sudo apt-get install gcc-mingw-w64

然后再编译:

CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build

https://github.com/mattn/go-sqlite3/issues/106

 

 附:go-sqlite3的作者说:go-sqlite3 is CGO module. So you need to enable CGO always.

https://github.com/mattn/go-sqlite3/issues/384

-- End --

posted @ 2017-03-02 11:02  ibg  阅读(1981)  评论(0编辑  收藏  举报