I'm trying to static link postgresql libpq with my program which connects to postgresql server, here is my docker file:
FROM nimlang/nim:alpine
RUN apk add --no-cache postgresql-dev
ENTRYPOINT ["sh", "-c"]
build:
docker build -t pgcompile .
compile:
docker run --rm -v (pwd):/mypgclient -w /mypgclient pgcompile "nim c --passL:'-static' --passL:'-lpq' -d:release -d:danger -d:nimDebugDlOpen mypgclient"
This compiles successfully, but I got error:
Dynamic loading not supported
could not load: libpq.so(.5|)
What is the problem?
I don't think you can just statically link libpq.so, you need libpg.a - static library file. I don't think apk add postgresql-dev gives you that, I think it only gives you the dynamically linked one. For static linking you probably would have to build libpq.a yourself from source. Libpq is a huge library you will also have to figure out two to deal with its dependencies: ssl, crypto zlib, iconv, ... I think it's going to take a long time to figure out.
If you are using docker why care about static linking?