Go-sqlite3: C source files not allowed when not using cgo: sqlite3-binding.c

Created on 29 Jun 2015  Â·  16Comments  Â·  Source: mattn/go-sqlite3

I create an application using this driver and works very well in OSX. Now i want to cross-compile for windows and after type GOOS=windows GOARCH=386 go build i get the following error C source files not allowed when not using cgo: sqlite3-binding.c
I installed all the necessary dependencies through goxc and i cross-compile almost every day to windows. The mentioned issues happens when i use this driver.
Any help appreciated.

Most helpful comment

This binding uses CGO and according to https://golang.org/cmd/cgo/ CGO is disabled by default when cross-compiling. You need to enable it explicitly by setting CGO_ENABLED=1 environment variable.

All 16 comments

I read it (is in the README) after post this question but im not sure what exactly do on OSX. I already have the native Windows toolchain (it was installed with goxc) but i'm kinda loss in the step 4.
Is there any tutorial or tips of how to do the equivalent thing on OSX without re-install the hole thing ?
Thanks in advance.

Am also seeing this error when running GOOS=linux GOARCH=amd64 go build.

Same. Although, in my case I was trying to use the goose tool on an ec2 box. When I cross compiled on my mac, I got the above error. When I compiled it directly on the linux box, I just got a no buildable Go source files error, because goose depends on this project.

I manually removed all reference to go-sqlite3 (I'm using mysql) and was able to get goose working right away. So this is definitely an issue with this repo if you want to use it on linux amd64.

selfie-0

This binding uses CGO and according to https://golang.org/cmd/cgo/ CGO is disabled by default when cross-compiling. You need to enable it explicitly by setting CGO_ENABLED=1 environment variable.

:+1: @kikht, I just had this issue and it's solved thanks to you ! :gift_heart:

@kikht +1 Tnx

Hi, i have the same problem.

If i set CGO_ENABLED=1 and compile for linux64 or win32 from my windows10, i have the following error:

C:\Users\xxxx\AppData\Local\Temp\go-build414971746\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 Error: Process ended with return value 2

Help :)

@Fruchtgummi are you trying cross compiling?

Yes, with others go-program it goes, but just now not with this sqlite.

Then, you need to use cross compiler not host compiler.

My cross-linux64.env

`# cross-compiler linux amd64

GOROOT=c:go
GOBIN=%GOROOT%\bin
GOARCH=amd64
GOOS=linux
CGO_ENABLED=1

GO15VENDOREXPERIMENT=1

PATH=C:\mingw-w64x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin;%PATH%

LITEIDE_GDB=gdb
LITEIDE_MAKE=mingw32-make
LITEIDE_TERM=%COMSPEC%
LITEIDE_TERMARGS=
LITEIDE_EXEC=%COMSPEC%
LITEIDE_EXECOPT=/C`

It that wrong? -> LITEIDE_MAKE=mingw32-make

you need to use C-compiler that can generate ELF binary. Not go compiler.

What?

I use mingw-w64 and also provides ELF binary, I complie other GO programm with C-components -everything goes?? I only have trouble with sqlite3.

Ah, I found this. So currently, you can do this on Windows.

https://github.com/golang/go/blob/master/src/cmd/go/build.go#L3015-L3019

export CC=arm-linux-gnueabihf-gcc-5; \
CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static" \
  -o "./bin/${GOOS}_${GOARCH}/the_app"
Was this page helpful?
0 / 5 - 0 ratings