Open
Description
Describe the bug
Cabal unconditionally invokes pkg-config --libs
when collecting arguments, which is not sufficient for certain static linking scenarios:
cabal/Cabal/src/Distribution/Simple/Configure.hs
Line 1640 in 00a2351
When statically linking, it should use pkg-config --static --libs
instead.
To Reproduce
- Download
hw-kafka-client
and change itsextra-libraries: rdkafka
topkgconfig-depends: rdkafka
. - Create a package with
build-depends: hw-kafka-client
, use acabal.project
file to have the test package use your localhw-kafka-client
and attempt to build it using a musl64 cross-toolchain (easiest to usehaskell.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 inlibrdkafka.a
. rdkafka.pc
correctly lists the-lssl
etc inLibs.private
.- Reading between the lines of the
pkg-config
manual, theLibs.private
are only added when statically linking. You can confirm this by runningpkg-config --static --libs rdkafka
andpkg-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 hasbuild-depends: hw-kafka-client
will not statically link (usingmusl64
cross-toolchain fromhaskell.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.
Activity