sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

The PostgreSQL engine requires cgo. Please set CGO_ENABLED=1

Open m1ker1n opened this issue 2 years ago • 12 comments

Version

1.17.2

What happened?

sqlc was installed by this:

go install github.com/kyleconroy/sqlc/cmd/sqlc@latest

Used

sqlc generate

As result got messages that I should set CGO_ENABLED=1.

Expected to generate go code.

Relevant log output

output:
db/migrations/0001_init.up.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
db/migrations/0002_ad.up.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
db/migrations/0003_file.up.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
db/migrations/0004_ad_attachment.up.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
db/migrations/0005_messenger.up.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.

go env:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/admin/.cache/go-build"
GOENV="/home/admin/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/admin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/admin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/e/qfbi/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4211620203=/tmp/go-build -gno-record-gcc-switches"

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

m1ker1n avatar Mar 15 '23 20:03 m1ker1n

i uninstall the Go install, and use only the snapd one, and worked like a charm

cavator avatar Mar 22 '23 00:03 cavator

Was having the same issue. Installed homebrew for linux, then ran brew install sqlc. Now the sqlc generate works fine.

Assbomber avatar May 13 '23 10:05 Assbomber

@m1ker1n Can you give us a bit more information about the Go installation you're using? I'm confused because go env claims that CGO_ENABLED is set to true.

kyleconroy avatar Jun 07 '23 00:06 kyleconroy

Same error here using windows WSL2 ubuntu 22.04 go version go1.20.5 linux/amd64

hamedtahmasebi avatar Jul 05 '23 17:07 hamedtahmasebi

same issue WSL ubuntu 22.04 go version 1.20.6 linux/amd64 go install .../sqlc

my go env VGO_ENABLED=1 but it still keeps giving the same error that I should enable CGO_ENABLED flag

utsavo-afk avatar Jul 21 '23 23:07 utsavo-afk

anyone found a workaround for this?

brlala avatar Aug 07 '23 09:08 brlala

For anyone around here using WSL. I tried the command with sudo one day and it started working out of nowhere🤦‍♂️. might be as simple as that, try it.

hamedtahmasebi avatar Aug 08 '23 11:08 hamedtahmasebi

Switch to docker version 🙌. Easy

Assbomber avatar Aug 08 '23 12:08 Assbomber

Yeah, for anyone encountering this issue, instead of running go install, just download the binary directly. Works for me

brlala avatar Aug 08 '23 15:08 brlala

I encountered this issue on WSL and ChromeOS linux environment. the issue occurred when CGO_ENABLED was 0 when I installed sqlc and turning it on afterwards didn't help.

I was able to reproduce it here are some logs:


$ go env -w CGO_ENABLED=0
$ go env CGO_ENABLED
0
$ go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
$ go env -w CGO_ENABLED=1
$ sqlc generate
# package database
sql/schema/001_users.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
sql/schema/002_users_apiKeys.sql:1:1: the PostgreSQL engine requires cgo. Please set CGO_ENABLED=1.
$ go env CGO_ENABLED
1
$ rm ~/go/bin/sqlc
$ go env -w CGO_ENABLED=1
$ go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# github.com/sqlc-dev/sqlc/cmd/sqlc
/usr/bin/ld: warning: x86_64.o: missing .note.GNU-stack section implies executable stack
/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
$ sqlc generate
$ go env CGO_ENABLED
1

I also installed couple of libraries like build-essential and libc-dev before I recreated the issue not sure if it made a difference.

teaampee avatar Aug 11 '23 20:08 teaampee

It's simple to fix, first you enable CGO

go env -w CGO_ENABLED=1

then you install gcc

sudo apt install build-essential

last you install sqlc again

go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest

ilessy avatar Sep 03 '23 01:09 ilessy

/This problem will occur if you use go install to download. I uninstalled the original one and installed it using brew and it was no problem.

HzTTT avatar Oct 18 '23 09:10 HzTTT