cross-compiling app with github package

170 views
Skip to first unread message

Jan Schaumann

unread,
Apr 5, 2013, 5:18:25 PM4/5/13
to golan...@googlegroups.com
Hello,

I'm trying to cross-compile a simple app that uses the
github.com/mattn/go-sqlite3 package. I've followed the steps on
http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go
to get Go cross compiled, and a simple hello-world program can be cross
compiled from OS X to Linux/amd64.

I've installed the github package via

go-linux-amd64 get github.com/mattn/go-sqlite3

and my GOROOT contains the right archive file in the correct place.

Building my applications succeeds as well:

$ go-linux-amd64 build short.go
file short
$ file short
short: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically
linked, not stripped
$

But when I try to execute this binary on the linux system (centos 5.5,
fwiw), I get an error opening the database file:

sql: unknown driver "sqlite3" (forgotten import?)

It appears the $GOROOT/pkg/linux_amd64/github.com/mattn/go-sqlite3.a was
not linked into the executable?

Thanks in advance for any help,
-Jan

Tamás Gulácsi

unread,
Apr 6, 2013, 3:11:42 AM4/6/13
to golan...@googlegroups.com
No, you have to import that driver with underscore, for the side effect of registering itself as an available sqlite driver.

minux

unread,
Apr 6, 2013, 4:25:31 AM4/6/13
to golan...@googlegroups.com
On Sat, Apr 6, 2013 at 5:18 AM, Jan Schaumann <jsch...@netmeister.org> wrote:
> I'm trying to cross-compile a simple app that uses the
> github.com/mattn/go-sqlite3 package. I've followed the steps on
> http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go
> to get Go cross compiled, and a simple hello-world program can be cross
> compiled from OS X to Linux/amd64.
>
> I've installed the github package via
>
> go-linux-amd64 get github.com/mattn/go-sqlite3
>
> and my GOROOT contains the right archive file in the correct place.
>
> Building my applications succeeds as well:
>
> $ go-linux-amd64 build short.go
> file short
> $ file short
> short: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically
> linked, not stripped
> $
cross platform cross-compilation doesn't support cgo, so you can't use
any cgo-dependent
packages (github.com/mattn/go-sqlite3 uses cgo).

Jan Schaumann

unread,
Apr 6, 2013, 9:54:25 AM4/6/13
to golan...@googlegroups.com
minux <minu...@gmail.com> wrote:

> cross platform cross-compilation doesn't support cgo, so you can't use
> any cgo-dependent
> packages (github.com/mattn/go-sqlite3 uses cgo).

Thanks. Is this something the compiler could detect and warn about?

-Jan
Reply all
Reply to author
Forward
0 new messages