Go-sqlite3: Error building go app : undefined: SQLiteConn

Created on 14 Sep 2016  Â·  18Comments  Â·  Source: mattn/go-sqlite3

....\github.com\mattn\go-sqlite3\tracecallback_noimpl.go:7: undefined: SQLiteConn

OS: Windows 10 Pro 64
c++ compiler framework: MinGW64

Most helpful comment

to be more clear CGO_ENABLED=1 is needed.

All 18 comments

can't reproduce this. what is different from general situation?

I have used the test code under "Quickstart" from https://github.com/go-gorp/gorp
I have go version go1.7.1 windows/amd64

I used "github.com/mattn/go-sqlite3" and it build and installed fine

Any other info you need Matt?

This is the error at the end of "go build test.go"
"#" github.com/mattn/go-sqlite3
....\github.com\mattn\go-sqlite3\tracecallback_noimpl.go:7: undefined: SQLiteConn

please try with go build -x on $GOPATH/github.com/mattn/go-sqlite3

What about go env ?

D:\Working\gosrc\github.com\mattn\go-sqlite3>go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Working\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\toolwindows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\brettm\AppData\Local\Temp\go-build709739654=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

I used "github.com/mattn/go-sqlite3" and it build and installed fine

But not? Is this an issue related on tests?

D:\Working\gosrc\github.com>
D:\Working\gosrc\github.com>rmdir /s mattn
mattn, Are you sure (Y/N)? y
D:\Working\gosrc\github.com>go get github.com/mattn/go-sqlite3
D:\Working\gosrc\github.com>

That is what I meant Matt, I did not get any errors when I installed it

Okay, then what is remaining issue?

Matt, I think if is a cross compiler issue
this works:
go build -v test.go

this does not:
D:\Working\gosrc\local\syslog-connector-go>set GOARCH=amd64

D:\Working\gosrc\local\syslog-connector-go>set GOOS=linux

D:\Working\gosrc\local\syslog-connector-go>go build -v test.go
...
log
database/sql
github.com/mattn/go-sqlite3
gopkg.in/gorp.v1
(#) github.com/mattn/go-sqlite3
....\github.com\mattn\go-sqlite3\tracecallback_noimpl.go:7: undefined: SQLiteConn

Further..
I used set CGO_ENABLED=1
and now have this problem (which seems to have progressed at least)

D:\Working\gosrc\local\syslog-connector-go>go build -v test.go
runtime/internal/sys
runtime/internal/atomic
...
strconv
(#) runtime/cgo
C:\Gosrc\runtime\cgo\gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
C:\Gosrc\runtime\cgo\gcc_linux_amd64.c:61:2: error: unknown type name 'sigset_t'
sigset_t ign, oset;
^~~~
C:\Gosrc\runtime\cgo\gcc_linux_amd64.c:66:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
sigfillset(&ign);
^~~~
C:\Gosrc\runtime\cgo\gcc_linux_amd64.c:61:16: error: unused variable 'oset' [-Werror=unused-variable]
sigset_t ign, oset;
^
~
cc1.exe: all warnings being treated as errors
regexp/syntax
...
database/sql
gopkg.in/gorp.v1

I think it is because cgo not supported for cross compilation in Go, I will move my dev environment to a linux container.
Thanks Matt, please close

On Linux I am unable to compile without cgo. Is there any solution to this?

$ CGO_ENABLED=0 go build --ldflags '-extldflags "-static"' -ldflags '-s' -a -installsuffix cgo
# github.com/mattn/go-sqlite3
../../../../github.com/mattn/go-sqlite3/tracecallback_noimpl.go:7: undefined: SQLiteConn

go-sqlite3 require ENABLE_CGO=1

to be more clear CGO_ENABLED=1 is needed.

using ubuntu 18.04

command :

CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o app.exe app.go

error :

gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?

@codenoid You need to set CC to a valid Windows cross compiler. By default you are using the one for your host (Linux).

@rittneje yea, just successfully compile my application in target host (windows)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  6Comments

mhat picture mhat  Â·  7Comments

student020341 picture student020341  Â·  9Comments

FlorianUekermann picture FlorianUekermann  Â·  5Comments

hackertron picture hackertron  Â·  10Comments