-
Notifications
You must be signed in to change notification settings - Fork 37
Description
I tried to investigate the problems I mentioned having in #25 (comment) . Turns out my linking problems were not about OpenSSL at all. It was the combination of Postgres 12 libpq
and static linking with Musl that broke the build.
Here's a script demonstrating the problem, using a simple C example program. (It uses Docker image I build as a part of my project https://gitlab.com/rust_musl_docker/image ):
#!/bin/sh -eu
> test.c cat << EOF
#include <libpq-fe.h>
int main() {
PQconnectStart("test");
}
EOF
> build_test.sh cat << EOF
#!/bin/sh
musl-gcc -c -I/musl/include test.c
musl-gcc -static -o test test.o -L /musl/lib/ -lpq
EOF
chmod 0755 build_test.sh
echo "Building a binary with Postgres 11.7"
docker run -it --rm \
-v "$PWD:/libworkdir" \
registry.gitlab.com/rust_musl_docker/image/base:openssl-1.1.1d_postgres-11.7 \
./build_test.sh
echo "Building a binary with Postgres 12.0"
docker run -it --rm \
-v "$PWD:/libworkdir" \
registry.gitlab.com/rust_musl_docker/image/base:openssl-1.1.1d_postgres-12.0 \
./build_test.sh
If I add the linker flags -lpgport
and -lpgcommon
like this:
musl-gcc -static -o test test.o -L /musl/lib/ -lpq -lpgport -lpgcommon
... it manages to build the binary.
I'm sure it's the same problem I'm encountering with pq-sys
because adding those linker flags to the flags Rust passes to cc
makes the binary to link.
I'm currently trying to engage with Postgres community to check whether the dependency to those two libraries are intentional or is there something I'm missing, so we'll know exactly what to fix.