Re: Build issue with postgresql 17 undefined reference to `pg_encoding_to_char' and `pg_char_to_encoding'

From: Mikael Sand <msand(at)seaber(dot)io>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Build issue with postgresql 17 undefined reference to `pg_encoding_to_char' and `pg_char_to_encoding'
Date: 2024-10-10 18:26:18
Message-ID: CAAwAxZdSu2jbsPcMzOMT0+ZiiyVNHf1k6gzKPeQqeTWSABbSvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

We use static linking and link time optimization to squeeze the last bits
of performance out of the code in our most performance-critical queries,
and it simplifies our security audits to have a static binary running
inside chainguard/static as the data we handle is sensitive/business
critical.

Wonderful, the build works when using -lpgcommon_shlib -lpgport_shlib
So this appears to imply that the output of `pkg-config -libs -static
libpq`is incorrect?

/app # pkg-config -libs -static libpq
> -L/usr/local/lib -lpq -L/usr/lib/llvm15/lib -L/usr/local/lib -lpgcommon
> -lpgport -lgssapi_krb5 -lm -lldap -lssl -lcrypto -ldl -pthread
>

On Thu, Oct 10, 2024 at 7:54 PM Aleksander Alekseev <
aleksander(at)timescale(dot)com> wrote:

> Mikael,
>
> On Thu, Oct 10, 2024 at 8:49 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >
> > Mikael Sand <msand(at)seaber(dot)io> writes:
> > > RUN clang++ -fno-common -static -o main main.cpp \
> > > -L/usr/local/lib -lpq -lpgcommon -lpgport \
> > > -lldap -lsasl2 -lssl -lcrypto -llber \
> > > -lgssapi_krb5 \
> > > -lkrb5 -lk5crypto -lcom_err -lkrb5support \
> > > -lgdbm
> >
> > The short answer here is that your link recipe is wrong, and has been
> > wrong right along, though you accidentally got away with it before.
> > The modules within libpq expect to be linked with libpgcommon_shlib
> > and libpgport_shlib, not libpgcommon/libpgport.
> >
> > Having external code that needs to know explicitly about every one
> > of a library's dependencies is one of many reasons why we discourage
> > static linking.
>
> May I ask what problem you are trying to solve with static linking in
> the first place?
>
> --
> Best regards,
> Aleksander Alekseev
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mikael Sand 2024-10-10 18:29:43 Re: Build issue with postgresql 17 undefined reference to `pg_encoding_to_char' and `pg_char_to_encoding'
Previous Message Jacob Champion 2024-10-10 18:25:18 Re: Converting tab-complete.c's else-if chain to a switch