Hi Commit cc8d4151 [*] introduced a dependency between some functions in libpgcommon and libpgfeutils, which is not reflected in the linker options provided when building an external program using PGXS, e.g. attempting to build the attached (trivial) example results in:
$ PATH=$PG_HEAD:$PATH USE_PGXS=1 make gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -ggdb -Og -g3 -fno-omit-frame-pointer -I. -I./ -I/home/ibarwick/devel/builds/HEAD/include/postgresql/server -I/home/ibarwick/devel/builds/HEAD/include/postgresql/internal -D_GNU_SOURCE -c -o pgxs-test.o pgxs-test.c gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -ggdb -Og -g3 -fno-omit-frame-pointer pgxs-test.o -L/home/ibarwick/devel/builds/HEAD/lib -Wl,--as-needed -Wl,-rpath,'/home/ibarwick/devel/builds/HEAD/lib',--enable-new-dtags -L/home/ibarwick/devel/builds/HEAD/lib -lpgcommon -lpgport -L/home/ibarwick/devel/builds/HEAD/lib -lpq -lpgcommon -lpgport -lpthread -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lrt -lcrypt -ldl -lm -o pgxs-test /home/ibarwick/devel/builds/HEAD/lib/libpgcommon.a(pgfnames.o): In function `pgfnames': /home/ibarwick/devel/postgresql/src/common/pgfnames.c:48: undefined reference to `__pg_log_level' /home/ibarwick/devel/postgresql/src/common/pgfnames.c:48: undefined reference to `pg_log_generic' /home/ibarwick/devel/postgresql/src/common/pgfnames.c:69: undefined reference to `__pg_log_level' /home/ibarwick/devel/postgresql/src/common/pgfnames.c:69: undefined reference to `pg_log_generic' /home/ibarwick/devel/postgresql/src/common/pgfnames.c:74: undefined reference to `__pg_log_level' /home/ibarwick/devel/postgresql/src/common/pgfnames.c:74: undefined reference to `pg_log_generic' collect2: error: ld returned 1 exit status make: *** [pgxs-test] Error 1 which is a regression compared to PG11 and earlier. Workaround/possible fix is to include "pgfeutils" in the "libpq_pgport" definition, i.e.: *** a/src/Makefile.global.in --- b/src/Makefile.global.in *************** libpq = -L$(libpq_builddir) -lpq *** 561,567 **** # on client link lines, since that also appears in $(LIBS). # libpq_pgport_shlib is the same idea, but for use in client shared libraries. ifdef PGXS ! libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq) libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq) else libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq) --- 561,567 ---- # on client link lines, since that also appears in $(LIBS). # libpq_pgport_shlib is the same idea, but for use in client shared libraries. ifdef PGXS ! libpq_pgport = -L$(libdir) -lpgcommon -lpgport -lpgfeutils $(libpq) libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq) else libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq) I presume a similar modification may need to be added to the following lines in that section but haven't had a chance to look in detail yet (and may be barking up the wrong tree entirely of course). [*] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=cc8d41511721d25d557fc02a46c053c0a602fed Regards Ian Barwick -- Ian Barwick https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
PROGRAM = pgxs-test OBJS = pgxs-test.o PG_CONFIG = pg_config PG_LIBS = $(libpq_pgport) PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS)
#include "postgres.h" #include "fmgr.h" int main(int argc, char **argv) { char **fnames = pgfnames("/tmp"); char *fname = fnames[0]; int total_names = 0; while (fname) { total_names++; fname = fnames[total_names]; } printf("total files: %i\n", total_names); pgfnames_cleanup(fnames); return 0; }