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

pkg-config support insufficient for certain static linking scenarios #7399

Open
JackKelly-Bellroy opened this issue May 18, 2021 · 2 comments
Labels
re: pkg-config Concerning pkg-config and pkgconfig-depends constraints

Comments

@JackKelly-Bellroy
Copy link

JackKelly-Bellroy commented May 18, 2021

Describe the bug
Cabal unconditionally invokes pkg-config --libs when collecting arguments, which is not sufficient for certain static linking scenarios:

ldflags <- pkgconfig ("--libs" : pkgs)

When statically linking, it should use pkg-config --static --libs instead.

To Reproduce

  1. Download hw-kafka-client and change its extra-libraries: rdkafka to pkgconfig-depends: rdkafka.
  2. Create a package with build-depends: hw-kafka-client, use a cabal.project file to have the test package use your local hw-kafka-client and attempt to build it using a musl64 cross-toolchain (easiest to use haskell.nix for this). Expect to see unresolved symbol errors of the form:
/nix/store/b07pcb91l2q1iasnqj74bajikd43b714-rdkafka-1.6.0-x86_64-unknown-linux-musl/lib/librdkafka.a(rdkafka_ssl.o):function rd_kafka_ssl_ctx_init: error: undefined reference to 'OpenSSL_version_num'

(The failure can be worked around with extra-libraries: rdkafka ssl crypto z.)

Cause of failure:

  • The linker command line mentions -lrdkafka but not -lssl -lcrypto, which are required by objects in librdkafka.a.
  • rdkafka.pc correctly lists the -lssl etc in Libs.private.
  • Reading between the lines of the pkg-config manual, the Libs.private are only added when statically linking. You can confirm this by running pkg-config --static --libs rdkafka and pkg-config --libs rdkafka and comparing their output.
  • Cabal only ever invokes pkg-config --libs as far as I can tell (see link at top of issue), so the musl64 build fails.
    A package that has build-depends: hw-kafka-client will not statically link (using musl64 cross-toolchain from haskell.nix) due to missing -lssl and -lcrypto on the linker command-line.

Expected behavior
Additional flags for static linking should make their way through to the linker command line, and the program should build without errors.

@JackKelly-Bellroy
Copy link
Author

example.tar.gz

Attached is a minimal reproduction case. unpack the tarball, cd into example and run the shell script - it will download a copy of hw-kafka-client and change it to use pkgconfig-depends. Then run nix-build and you'll see the linker errors I'm talking about. Make sure to set up the IOHK nix cache first.

@phadej
Copy link
Collaborator

phadej commented May 18, 2021

See #6935 (comment)

@andreasabel andreasabel added the re: pkg-config Concerning pkg-config and pkgconfig-depends constraints label May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: pkg-config Concerning pkg-config and pkgconfig-depends constraints
Projects
None yet
Development

No branches or pull requests

3 participants