Good day! Error launching a file compiled from under Windows on a linux machine:

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

Everything is working fine on Windows

I tried the driver github.com/mattn/go-sqlite3 and github.com/mxk/go-sqlite

Compilation:

 set GOOS=linux go build entry.go 

Code: http://pastebin.com/8iqvhp1n
Import Library: _ "github.com/mattn/go-sqlite3"

Why is this happening and how can this be solved?

Go 1.7.4, Windows 10, Ubuntu 04/16/1

  • Add the minimum required example to the question (information on the link can be deleted or changed). - Mikhail Vaysman
  • Is your compilation successful? sqlite3 is written in C, therefore it should not cross-compile without a cross compiler. - Ainar-G
  • There are no errors in the console when compiling. "cross compiler si", is it possible in more detail? - Festelo
  • In order to compile code from under one operating system for another, you need a cross compiler. In go, the usual compiler is the default crosscompiler, but in C this is not the case. Try doing a go build with GOOS=linux CGO_ENABLED=1 . - Ainar-G
  • # runtime / cgo C: \ Users \ eee \ AppData \ Local \ Temp \ go-build336598898 \ runtime \ cgo_obj_cgo_main.c: 1: 0: error: -fPIC ignored for target (all code is position independent) [-Werror] int main () {return 0; } ^ cc1.exe: all warnings being treated as errors ( pastebin.com/8EAsRD9i ) - Festelo

1 answer 1

The problem is that when you get a package (or assembly) go get -u github.com/mattn/go-sqlite3 for Windows, the sqlite driver is built for the current platform, you need to build the linux driver itself:

 set GOOS=linux go build -v github.com/mattn/go-sqlite3 

After that, already collect your application

Cross compiling Go on Windows (github golang wiki)