Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql-libpq dependent app failing to link to openssl with musl builds #1607

Closed
mzabani opened this issue Aug 21, 2022 · 5 comments
Closed
Labels
bug Something isn't working wontfix

Comments

@mzabani
Copy link

mzabani commented Aug 21, 2022

I'm trying to build an executable with musl but it's giving me errors like the following:

/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1643:0: error:
     error: undefined reference to 'SSL_get_version'

I'm on haskell.nix 5545098 with nixpkgs following haskellNix/nixpkgs-2205, stackage nightly-2022-08-14 with GHC 9.2.4 and I'm using flakes.

I also applied #1056 in a stack.yaml project, which means I added the following to my stack.yaml file:

flags:
  postgresql-libpq:
    use-pkg-config: true

And it did get me past some errors related to pg_config IIRC. I have my code pushed to https://github.com/mzabani/codd/tree/issue-110-build-codd-statically if more details are not necessary, but it's sadly not a small app. I'll paste below what I have in flake.nix that I think is relevant to the issue, but please let me know if I can help with more info.

Relevant bits of flake.nix:

modules = [{
packages.codd.components.exes.codd = {
                    dontStrip = false;
                    configureFlags = [
                      # The following tries what's suggested in https://github.com/input-output-hk/haskell.nix/pull/1056,
                      # but I wasn't able to make it work yet
                      # "--ghc-option=-optl=-I${pkgs.openssl.dev}/include/openssl"
                      # The order of -lssl and -lcrypto is important here
                      "--ghc-option=-optl=-lssl"
                      "--ghc-option=-optl=-lcrypto"
                      "--ghc-option=-optl=-L${pkgs.openssl.out}/lib"

                      # I'm not even sure how many of these are necessary, but some definitely are
                      # to avoid 'undefined reference to' linking errors.
                      "--ghc-option=-optl=-L${pkgs.postgresql.out}/lib"
                      "--ghc-option=-optl=-I${pkgs.postgresql.out}/include"
                      "--ghc-option=-optl=-lpq"
                      "--ghc-option=-optl=-lpgcommon"
                      "--ghc-option=-optl=-lpgport"
                      "--ghc-option=-optl=-lecpg"
                    ];
                  };
                }];
Output of nix log /nix/store/bfrg4vxq8in8xv6vslm42ykf8jic3871-codd-exe-codd-x86_64-unknown-linux-musl-0.1.0.0.drv:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/scs6kx8agsj1vldf6q9m0r8s6mrfy60g-source-root-exe-codd
source root is source-root-exe-codd
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
Configure flags:
--prefix=/nix/store/76drj8a4na4q3w0l0v3l5yri3gk5yw3d-codd-exe-codd-x86_64-unknown-linux-musl-0.1.0.0 exe:codd --package-db=clear --package-db=/nix/store/gdn3cf1dwgjjna2v3qyjys3q194x1846-x86_64-unknown-linux-musl-codd-exe-codd-0.1.0.0-config/lib/x86_64-unknown-linux-musl-ghc-8.10.7/package.conf.d --exact-configuration --dependency=codd=codd-0.1.0.0-9ssGT7mdG0A687Ch87j3nh --dependency=monad-logger=monad-logger-0.3.36-KT0nIdxz3O1HpZVfz7huVM --dependency=optparse-applicative=optparse-applicative-0.16.1.0-2C26jThKFSfBhyDOO7aavt --dependency=postgresql-simple=postgresql-simple-0.6.4-6M8fJJnY6mBDZ7XIHuLK13 --dependency=postgresql-libpq=postgresql-libpq-0.9.4.3-CkWBavwM0DACTjqZZdMqN8 --dependency=text=text-1.2.4.1-3ons0v27Yr7GZbokcYUGS --dependency=time=time-1.9.3-AAq60BtyTvLBxnbhpLzOg0 --dependency=array=array-0.5.4.0 --dependency=base=base-4.14.3.0 --dependency=deepseq=deepseq-1.4.4.0 --dependency=ghc-boot-th=ghc-boot-th-8.10.7 --dependency=ghc-prim=ghc-prim-0.6.1 --dependency=integer-gmp=integer-gmp-1.0.3.0 --dependency=pretty=pretty-1.1.3.6 --dependency=rts=rts --dependency=template-haskell=template-haskell-2.16.0.0 --with-ghc=x86_64-unknown-linux-musl-ghc --with-ghc-pkg=x86_64-unknown-linux-musl-ghc-pkg --with-hsc2hs=x86_64-unknown-linux-musl-hsc2hs --with-gcc=x86_64-unknown-linux-musl-cc --with-ld=x86_64-unknown-linux-musl-ld.gold --ghc-option=-optl-fuse-ld=gold --ld-option=-fuse-ld=gold --with-ar=x86_64-unknown-linux-musl-ar --with-strip=x86_64-unknown-linux-musl-strip --disable-executable-stripping --disable-library-stripping --disable-library-profiling --disable-profiling --enable-static --enable-shared --disable-coverage --enable-library-for-ghci --disable-executable-dynamic --ghc-option=-optl=-pthread --ghc-option=-optl=-static --datadir=/nix/store/pg1j02k3k4ly7ajfc5xznal3ckib909z-codd-exe-codd-x86_64-unknown-linux-musl-0.1.0.0-data/share/x86_64-unknown-linux-musl-ghc-8.10.7 --enable-split-sections --ghc-option=-optl=-lssl --ghc-option=-optl=-lcrypto --ghc-option=-optl=-L/nix/store/nwf2y0nc48ybim56308cr5ccvwkabcqc-openssl-1.1.1q/lib --ghc-option=-optl=-L/nix/store/g5sxcmvhw3881yljfhkawz1kf7hb9xd9-postgresql-14.4/lib --ghc-option=-optl=-I/nix/store/g5sxcmvhw3881yljfhkawz1kf7hb9xd9-postgresql-14.4/include --ghc-option=-optl=-lpq --ghc-option=-optl=-lpgcommon --ghc-option=-optl=-lpgport --ghc-option=-optl=-lecpg
Configuring executable 'codd' for codd-0.1.0.0..
Warning: 'hs-source-dirs: src' directory does not exist.
Warning: 'hs-source-dirs: test' directory does not exist.
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Preprocessing executable 'codd' for codd-0.1.0.0..
Building executable 'codd' for codd-0.1.0.0..
[1 of 1] Compiling Main ( app/Main.hs, dist/build/codd/codd-tmp/Main.o )
exprType TYPE: a_a4MB
exprType TYPE: a_a4MB
Linking dist/build/codd/codd ...
/nix/store/khasxzzwi4vwh6zg6j1yczk8l0xsrj54-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld.gold: error: cannot find -lssl
/nix/store/khasxzzwi4vwh6zg6j1yczk8l0xsrj54-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld.gold: error: cannot find -lcrypto

�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1558:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_reason_error_string'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:816:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'TLS_method'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:816:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_new'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:843:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_set_default_passwd_cb'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:844:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_set_default_passwd_cb_userdata'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:848:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_set_options'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:913:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1062:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_new'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1063:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_set_ex_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1786:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_new'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1792:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_set_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1794:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_set_bio'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1795:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_int_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1082:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1332:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_clear_options'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1143:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_by_id'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1156:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_init'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1170:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_load_private_key'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1186:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_use_PrivateKey'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:867:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:869:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1027:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1098:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1100:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1308:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_check_private_key'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1310:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1324:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_set_verify'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:896:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:898:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1731:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_s_socket'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1735:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_get_new_index'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1739:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_new'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1747:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_write'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1748:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_read'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1749:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_gets'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1749:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_gets'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1750:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_puts'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1750:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_puts'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1751:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1751:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1752:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_create'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1752:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_create'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1753:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_destroy'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1753:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_destroy'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1754:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_get_callback_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1754:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_set_callback_ctrl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1756:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_meth_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1789:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_put_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1039:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_use_certificate_chain_file'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1330:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_set_options'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:932:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_load_verify_locations'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:944:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_get_cert_store'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:963:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_STORE_load_locations'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:970:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_clear_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1276:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_use_PrivateKey_file'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1292:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_use_PrivateKey_file'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:965:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_STORE_set_flags'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1194:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_finish'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1195:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:892:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:863:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CTX_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1671:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_get_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1672:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_clear_flags'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1685:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_set_flags'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1701:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_get_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1702:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_clear_flags'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1715:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'BIO_set_flags'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:165:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_clear_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_read'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:167:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:270:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_pending'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:283:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_clear_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:284:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_write'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:285:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:396:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_get_signature_nid'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:396:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OBJ_find_sigid_algs'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:417:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OBJ_nid2sn'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:417:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'EVP_get_digestbyname'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:428:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_digest'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:414:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'EVP_sha256'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:420:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OBJ_nid2sn'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:525:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_get_ext_d2i'�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OPENSSL_sk_num'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OPENSSL_sk_value'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:496:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ASN1_STRING_get0_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:500:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ASN1_STRING_length'�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'GENERAL_NAME_free'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OPENSSL_sk_pop_free'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:569:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_get_subject_name'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:574:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_NAME_get_index_by_NID'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:580:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_NAME_get_entry'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:579:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_NAME_ENTRY_get_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:496:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ASN1_STRING_get0_data'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:500:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ASN1_STRING_length'�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'GENERAL_NAME_free'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/nix/store/vjmwhzy46741shl5afrsw6b5cp80xahq-openssl-x86_64-unknown-linux-musl-1.1.1q-dev/include/openssl/x509v3.h:166:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OPENSSL_sk_pop_free'�[0m�[0m
�[;1m�[34m |�[0m�[0m
�[;1m�[34m166 |�[0m�[0m �[;1m�[31mD�[0m�[0mEFINE_STACK_OF(GENERAL_NAME)
�[;1m�[34m |�[0m�[0m�[;1m�[31m ^�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:713:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'OPENSSL_init_ssl'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1481:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_shutdown'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1482:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1491:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'X509_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1498:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_finish'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1499:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ENGINE_free'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1345:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'ERR_clear_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1346:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_connect'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1443:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_peer_certificate'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1349:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_error'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1631:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_current_cipher'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1631:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CIPHER_get_bits'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1637:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_current_cipher'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1640:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_current_compression'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1643:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_get_version'�[0m�[0m
�[0m�[0m�[0m
�[;1m/build/postgresql-14.4/src/interfaces/libpq/fe-secure-openssl.c:1637:0: �[;1m�[31merror:�[0m�[0m�[;1m�[0m�[0m�[;1m
error: undefined reference to 'SSL_CIPHER_get_name'�[0m�[0m
�[0m�[0m�[0m/nix/store/khasxzzwi4vwh6zg6j1yczk8l0xsrj54-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld.gold: internal error in format_file_lineno, at dwarf_reader.cc:2713
collect2: error: ld returned 1 exit status
`x86_64-unknown-linux-musl-cc' failed in phase `Linker'. (Exit code: 1)

Sorry for the bad formatting above.
One thing that stands out to me - although I don't have almost any experience with linkers - are the lines:

Linking dist/build/codd/codd ...
/nix/store/khasxzzwi4vwh6zg6j1yczk8l0xsrj54-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld.gold: error: cannot find -lssl
/nix/store/khasxzzwi4vwh6zg6j1yczk8l0xsrj54-x86_64-unknown-linux-musl-binutils-2.38/bin/x86_64-unknown-linux-musl-ld.gold: error: cannot find -lcrypto

And I think that's why errors are happening. It's perplexing to me, since the configure flags look right (both -lssl and -lcrypto are there, and the -L for the folder with libcrypto.so and libssl.so is correct), and using objdump -T a little bit I see some of these unknown symbols do exist in those .so files.

I have tried disabling stripping, a different Stackage LTS with GHC 8.10.7, changing the order of -l options, and perhaps a few other things, but nothing seems to fix the problem.

Thanks in advance.

@mzabani
Copy link
Author

mzabani commented Aug 21, 2022

Sorry for spamming. I just learned that .a files are required for static linking, and the openssl folder only contains .so files. I tried using "--ghc-option=-optl=-L${pkgs.pkgsStatic.openssl.out}/lib" in the configure flags instead, but that leads to other far less familiar (to me) linking errors.

@michaelpj
Copy link
Collaborator

Related? #782

@mzabani
Copy link
Author

mzabani commented Aug 22, 2022

I think the errors there are different from this? At least it seems to me some of the problems mentioned by the OP like systemd being enabled in postgres compilation have been fixed (as far as I'm aware), and the problem with pg_config also can be worked around by following #1056 like I did here too.

@yvan-sraka yvan-sraka added the bug Something isn't working label Sep 20, 2022
@stale
Copy link

stale bot commented Jan 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 18, 2023
@mzabani
Copy link
Author

mzabani commented Feb 19, 2023

I was finally able to build statically linked executables. It involved mostly three things AFAICT:

  1. Changing flags in stack.yaml as Fix for postgresql-libpg and musl (fixes #948) #1056 suggests:
flags:
  postgresql-libpq:
    use-pkg-config: true
  1. Disabling tests for postgresql with musl as one of them fails (link to a working commit):
        libpqOverlay = final: prev:
          prev // (prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl {
            postgresql =
              prev.postgresql.overrideAttrs (_: { doCheck = false; });
          });
        overlays = [
          libpqOverlay
          # overlay from haskell.nix here
  1. The following configure flags (link to a working commit)
                      configureFlags = [
                        "--ghc-option=-optl=-L${final.pkgsCross.musl64.openssl.out}/lib"
                        "--ghc-option=-optl=-lssl"
                        "--ghc-option=-optl=-lcrypto"

                        "--ghc-option=-optl=-L${final.pkgsCross.musl64.postgresql.out}/lib"
                        "--ghc-option=-optl=-lpgcommon"
                        "--ghc-option=-optl=-lpgport"
                      ];

Other things worth mentioning for my working example are haskell.nix locked to c2f1434, nixpkgs following haskell.nix's nixpkgs-unstable and stackage LTS 18.28 and GHC 9.0.2. Hopefully these can be changed without breaking this solution.

I'm not sure if there's something that can be done on haskell.nix's side to make this work automatically. If there is something I can help with in that direction, please give me some pointers and I'd be glad to contribute.

@stale stale bot closed this as completed Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix
Projects
None yet
Development

No branches or pull requests

3 participants