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

The PostgreSQL engine requires cgo. Please set CGO_ENABLED=1 #2149

Open
m1ker1n opened this issue Mar 15, 2023 · 12 comments
Open

The PostgreSQL engine requires cgo. Please set CGO_ENABLED=1 #2149

m1ker1n opened this issue Mar 15, 2023 · 12 comments

Comments

@m1ker1n
Copy link

m1ker1n commented Mar 15, 2023

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 m1ker1n added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 15, 2023
@cavator
Copy link

cavator commented Mar 22, 2023

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

@Assbomber
Copy link

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

@kyleconroy
Copy link
Collaborator

@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 kyleconroy removed the triage New issues that hasn't been reviewed label Jun 7, 2023
@hamedtahmasebi
Copy link

hamedtahmasebi commented Jul 5, 2023

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

@utsavo-afk
Copy link

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

@brlala
Copy link

brlala commented Aug 7, 2023

anyone found a workaround for this?

@hamedtahmasebi
Copy link

hamedtahmasebi commented Aug 8, 2023

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.

@Assbomber
Copy link

Assbomber commented Aug 8, 2023

Switch to docker version 🙌. Easy

@brlala
Copy link

brlala commented Aug 8, 2023

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

@teaampee
Copy link

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.

@ilessy
Copy link

ilessy commented Sep 3, 2023

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

@HzTTT
Copy link

HzTTT commented Oct 18, 2023

/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.

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

No branches or pull requests

10 participants