go-sqlite3
go-sqlite3 copied to clipboard
Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work.
go-sqlite3 - tag v1.14.3
I'm building app in the goreleaser in docker environment. I read on README:
If you want to build your app using go-sqlite3, you need gcc. However, after you have built and installed go-sqlite3 with go install github.com/mattn/go-sqlite3 (which requires gcc), you can build your app without relying on gcc in future.
I'm running:
CGO_ENABLED=1 go install github.com/mattn/go-sqlite3
goreleaser --snapshot --rm-dist
goreleaser.yml:
builds:
binary: [...]
env:
- CGO_ENABLED=0
goarch:
- amd64
goos:
- linux
and the error is:
./myapp
2020-09-17T14:24:42.648+0200 INFO app/db.go:15 using database ./app.sqlite
panic: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
CGO_ENABLED=1 go install github.com/mattn/go-sqlite3
go build
./app
gives same error so it is not related to the goreleaser itself
I don't think the statement in the README is true. (Or at least, isn't true anymore.)
CGO_ENABLED=1 go install github.com/mattn/go-sqlite3
go build
./app
In this example, when you run go build (presumably with CGO_ENABLED=0), the Go compiler recompiles this library without cgo. To my knowledge, there is no way to force the Go compiler to use a pre-built version of a library, and if detects any changes (including enabling/disabling cgo), it will recompile.
I'm facing the same issue.
same issues here
I fixed it with adding CGO_ENABLED=1 but getting this to work with windows or even some cpu arch is challenging! https://github.com/Clivern/Chaos/blob/main/.goreleaser.yml#L19-L27
I ran into this using go run . Had to run apt install build-essential on the host and then all was well.
@aviddiviner Thanks man my tests were not building I was using sqlite database for go application, getting this error -
failed to initialize database, got error %v, /var/lib/jenkins/workspace/GoBuildTest/repository/repository.go:80%!(EXTRA *errors.errorString=Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub)
I was using it as a part of jenkins build process, and my jenkins server was running on EC2 ubuntu machine, with build-essential this worked fine.
If you are using M1 Mac and have specified the environment variable GOARCH=amd64, you will need to change it as follows. (This is my minor past solution...)
go env -w GOARCH=arm64
same issues here
Has anyone managed to solve this in a windows environment?
Has anyone managed to solve this in a windows environment?
go env -w CGO_ENABLED=1