Issue building go-sqlite3 with linking to libsqllite3 under macos 10.15.2
Hi;
I'm having issues trying to build go-sqlite3 linking to sqllite3 under macos 10.15.2.
[go-sqlite3]$ go build --tags "libsqlite3 darwin"
# github.com/mattn/go-sqlite3
./sqlite3_load_extension.go:25:8: could not determine kind of name for C.sqlite3_enable_load_extension
./sqlite3_load_extension.go:33:8: could not determine kind of name for C.sqlite3_load_extension
I'm actually trying to solve an issue getting an externally compiled sqlite extension to run under go-sqlite3, but that's much harder issue to describe and my googling lead me to trying to go build with libsqlite3, so thought I'd try and figure this issue out first.
I've tried the suggestions of using brew's gcc here #126 and here #95 but with no luck.
Any thoughts? Thanks
[go-sqlite3]$ go version
go version go1.14.5 darwin/amd64
[go-sqlite3]$ uname -a
Darwin mac.local 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64
[go-sqlite3]$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gav/Library/Caches/go-build"
GOENV="/Users/gav/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gav/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="GCC-10"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/var/folders/wz/nf87bmg16rnf77tn3z6753r00000gn/T/go-build418741130=/tmp/go-build -gno-record-gcc-switches -fno-common"
I'm not familier to macOS but
CC="GCC-10"
Is this right?
Sorry, that was an 'unclean' env from my trying out the suggestions in https://github.com/mattn/go-sqlite3/issues/80#issuecomment-26681977
Here's the clean one:
[go-sqlite3]$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gav/Library/Caches/go-build"
GOENV="/Users/gav/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gav/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wz/nf87bmg16rnf77tn3z6753r00000gn/T/go-build917423159=/tmp/go-build -gno-record-gcc-switches -fno-common"
If the clang can compile generic C source, this error won't reproduce. maybe.
Sorry I don't follow;
With the above go env here's the outputs I get:
[go-sqlite3]$ go build
No errors
[go-sqlite3]$ go build --tags "darwin"
No errors
[go-sqlite3]$ go build --tags "libsqlite3 darwin"
# github.com/mattn/go-sqlite3
./sqlite3_load_extension.go:25:8: could not determine kind of name for C.sqlite3_enable_load_extension
./sqlite3_load_extension.go:33:8: could not determine kind of name for C.sqlite3_load_extension
Could you please try:
$ go build --tags "libsqlite3 darwin" -v -x
Sure:
[go-sqlite3]$ go build --tags "libsqlite3 darwin" -v -x
WORK=/var/folders/wz/nf87bmg16rnf77tn3z6753r00000gn/T/go-build719395410
github.com/mattn/go-sqlite3
mkdir -p $WORK/b001/
cd /Users/gav/gocode/src/github.com/mattn/go-sqlite3
CGO_LDFLAGS='"-g" "-O2" "-L/usr/local/opt/sqlite/lib" "-lsqlite3"' /usr/local/Cellar/go/1.14.5/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/b001/ -importpath github.com/mattn/go-sqlite3 -- -I $WORK/b001/ -g -O2 -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DISABLE_INTRINSIC -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -DUSE_LIBSQLITE3 -I/Users/gav/gocode/src/github.com/mattn/go-sqlite3 ./backup.go ./callback.go ./error.go ./sqlite3.go ./sqlite3_context.go ./sqlite3_libsqlite3.go ./sqlite3_load_extension.go ./sqlite3_opt_userauth_omit.go ./sqlite3_other.go ./sqlite3_type.go
# github.com/mattn/go-sqlite3
./sqlite3_load_extension.go:25:8: could not determine kind of name for C.sqlite3_enable_load_extension
./sqlite3_load_extension.go:33:8: could not determine kind of name for C.sqlite3_load_extension
As far as I can see the log, header files seems not be included since -I flag is not specified to /usr/local/opt/sqlite/include ?
Awesome thanks, adding in the brew's version of sqllite's include files in the CGO_CFLAGS env let it compile!
CGO_CFLAGS="-I/usr/local/opt/sqlite3/include" go build --tags "libsqlite3 darwin" -v -x
I'll go see if this helps my other issue. Thanks for the timely support!