Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cadizjavier opened this issue Jun 29, 2015 · 16 comments
Closed

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

cadizjavier opened this issue Jun 29, 2015 · 16 comments

Comments

@cadizjavier
Copy link

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.

@mattn
Copy link
Owner

mattn commented Jun 29, 2015

@cadizjavier
Copy link
Author

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.

@djbobbydrake
Copy link

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

@kevin-cantwell
Copy link

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

@kikht
Copy link

kikht commented Oct 11, 2015

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.

@SiegfriedEhret
Copy link

👍 @kikht, I just had this issue and it's solved thanks to you ! 💝

@gi4nks
Copy link

gi4nks commented Apr 8, 2016

@kikht +1 Tnx

@Fruchtgummi
Copy link

Fruchtgummi commented Jul 14, 2016

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 :)

@mattn
Copy link
Owner

mattn commented Jul 14, 2016

@Fruchtgummi are you trying cross compiling?

@Fruchtgummi
Copy link

Fruchtgummi commented Jul 14, 2016

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

@mattn
Copy link
Owner

mattn commented Jul 14, 2016

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

@Fruchtgummi
Copy link

Fruchtgummi commented Jul 14, 2016

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-w64\x86_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

@mattn
Copy link
Owner

mattn commented Jul 14, 2016

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

@Fruchtgummi
Copy link

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.

@mattn
Copy link
Owner

mattn commented Jul 14, 2016

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

gjrtimmer added a commit to gjrtimmer/go-sqlite3 that referenced this issue May 26, 2018
Compile Section Closes mattn#175
Compile Section Closes mattn#201
Compile Section Closes mattn#206
Compile Section Closes mattn#404
Compile Section Closes mattn#217
Compile Section Closes mattn#224
Compile Section Closes mattn#234
Compile Section Closes mattn#242
Feature table Closes mattn#255
Description Section Closes mattn#232
Golang:1.6 not supported Closes mattn#272
Golang:1.5 not supported + compilation section Closes mattn#283
usleep Implemented Closes mattn#285
FAQ Section Closes mattn#289
Compile Section closes mattn#295
FAQ Section Closes mattn#305
PR339 Closes mattn#318 mattn#321
Compilation Section Closes mattn#341
PR407 Closes mattn#364
Feature `sqlite_vtable` Closes mattn#393
Compile Section Closes mattn#416
sqlite_trace feature Closes mattn#433
Compilation Section Closes mattn#435
Compilation Section Closes mattn#443
Golang:1.6 Not Supported Closes mattn#445
Compilation Section Closes mattn#451
Compilation Section Closes mattn#467
Compilation Section Closes mattn#491
Compilation Section Closes mattn#495
Compilation Section Closes mattn#505
Compilation Section Closes mattn#557
Compilation Section Closes mattn#560
@mattn mattn closed this as completed in c9394b1 May 27, 2018
@peterwillcn
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants