Error with CSFLE mongodb golang drivers

Is anyone facing this issue while trying to go build with cse tags for CSFLE ?

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -installsuffix cgo -tags cse -o /Users/techno/go/src/github.com/100mslive/rpcaccounts/bin/server /Users/techno/go/src/github.com/100mslive/rpcaccounts/cmd/server/main.go

go.mongodb.org/mongo-driver/x/mongo/driver

…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:44:35: undefined: mongocrypt.MongoCrypt
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:82:25: undefined: mongocrypt.MongoCrypt
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:250:79: undefined: mongocrypt.Context
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:278:74: undefined: mongocrypt.Context
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:297:71: undefined: mongocrypt.Context
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:314:72: undefined: mongocrypt.Context
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:334:50: undefined: mongocrypt.Context
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:349:47: undefined: mongocrypt.KmsContext
…/…/…/…/pkg/mod/go.mongodb.org/mongo-driver@v1.11.2/x/mongo/driver/crypt.go:453:79: undefined: mongocrypt.Context

go 1.19
go.mongodb.org/mongo-driver v1.11.2

Hey @Aakash_Bajaj welcome and thanks for the question! I suspect your issue is related to disabling CGO with the environment variable CGO_ENABLED=0 in your Go build command. The CSFLE feature in the MongoDB Go driver requires the libmongocrypt C extension, so requires CGO to be enabled.

Are you able to build if you include CGO_ENABLED=1 instead?

1 Like

Hey @Matt_Dale. Thanks for the response.
Yeah CGO_ENABLED=1 fixed the issue.

1 Like