SQLite3 usage with CGO_ENABLE build flag error
See original GitHub issueSummary
Attempting to use the SQLite3 database backend for sharing links fails because the binary was not complied with CGO_ENABLED=1
.
Goal
The project advertises the ability to use SQLite3 as a backend for the link sharing functionality.
Expected Outcome
When the binary or docker container is ran with the following parameters, the sharable links will be stored in an SQLite3 database in the given location: --shared-links.sql.driver="sqlite3" --shared-links.sql.dsn="/PATH"
.
Actual Outcome
The program throws the following error and fails to run: caller=main.go:191 level=error msg="Error initializing link sharer." err="error creating SQL link sharer: error enabling foreign key support: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub"
Reproduction
The below demonstrates a method of reproducing this issue, using both the official standalone binary and the Docker container.
Standalone Binary (downloaded from GitHub release)
~/promlens-0.1.0.linux-amd64$ sha256sum promlens
f2c9a5ae428aa0a3a7097b8422b946a0289cb09bf2cebe952af4cfb78f6463ae promlens
~/promlens-0.1.0.linux-amd64$ file promlens
promlens: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=K5nNTk_EsJ11Qmo3OmoO/Z9WIbgyQRzHs5Bzv3Nbq/vrkUmd1oyhisKw0i8n6c/OsFH0xvAPR6Nx3LVqG4n, with debug_info, not stripped
~/promlens-0.1.0.linux-amd64$ ./promlens --shared-links.sql.driver="sqlite3" --shared-links.sql.dsn="~"
caller=main.go:191 level=error msg="Error initializing link sharer." err="error creating SQL link sharer: error enabling foreign key support: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub"
Docker Container
$ docker run --rm prom/promlens --shared-links.sql.driver="sqlite3" --shared-links.sql.dsn="/tmp/promlens-links.db"
caller=main.go:191 level=error msg="Error initializing link sharer." err="error creating SQL link sharer: error enabling foreign key support: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub"
Additional Information
The go-sqlite3 repo contains the following text confirming the above:
go-sqlite3 is cgo package. 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. Important: because this is a CGO enabled package, you are required to set the environment variable CGO_ENABLED=1 and have a gcc compile present within your path. (https://github.com/mattn/go-sqlite3#installation)
Investigation
I have attempted to build the binary myself with the CGO_ENABLED
flag set to 1
in several ways with no success.
These include setting system and Go environment variables:
# go env | grep CGO_ENABLED && env | grep CGO_ENABLED
CGO_ENABLED="1"
CGO_ENABLED=1
And updating line 198 of Makefile.common to the following: CGO_ENABLED=1 $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
.
I have also confirmed that the build process (specifically $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
) had the CGO_ENABLED environment variable set to 1, by reviewing the process’ environment file, at /proc/#####/environ
.
I have also confirmed that gcc
is installed on the system that the above build was attempted on.
Despite all of these settings, a rebuilt binary still reports the same error.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
I got a PR half done to switch to the other sqlite library. I’ll finish it up and send it out.
Well that would explain it! Thanks for the info 😃