Search code examples
postgresqlgocgopostgres-fdwsteampipe

Upgrading `go version` for `CGO` a Postgres FDW project


I am trying to build the steampipe-postgres-fdw project in a Mac M1 with the latest go version (1.21).

It currently uses go version 1.19.

The FDW is designed to work with Postgresql 14.

The project comes with a Makefile which generates the go files with the C import headers (relies on the pg_config in $PATH).

I changed the go directive in the go.mod file (go mod edit --go 1.21), but when I run make, I hit upon the error below:

Undefined symbols for architecture arm64:
  "_res_9_nclose", referenced from:
      _internal/syscall/unix.libresolv_res_9_nclose_trampoline.abi0 in steampipe_postgres_fdw.a(go.o)
  "_res_9_ninit", referenced from:
      _internal/syscall/unix.libresolv_res_9_ninit_trampoline.abi0 in steampipe_postgres_fdw.a(go.o)
  "_res_9_nsearch", referenced from:
      _internal/syscall/unix.libresolv_res_9_nsearch_trampoline.abi0 in steampipe_postgres_fdw.a(go.o)
ld: symbol(s) not found for architecture arm64

Solution

  • Adding a -tags=netgo to go build resolved the issue.

    The writeup here is a great reference on how dynamic linking works in go.

    Caution: As @kostix mentions, this uses the go DNS resolver, "whose behavior might slightly deviate from "typically expected" behavior in some subtle cases"