Hw-kafka issues cabal

Greetings, I’m trying to use hw-kafka-client, but cabal says this when I run cabal build

Configuring library for hw-kafka-client-5.3.0..
Error: cabal-3.10.3.0: Missing dependency on a foreign library:

I’m using macOS, librdkafka is installed via brew

When I install hw-kafka-client I’ve put extra flags to find where include and lib folders for librdkafka exist

cabal install hw-kafka-client --extra-include-dirs=/opt/homebrew/Cellar/librdkafka/2.6.1/include --extra-lib-dirs=/opt/homebrew/Cellar/librdkafka/2.6.1/lib

It was build successfully

However, when I put hw-kafka-client to cabal file it starts telling that hw-kafka-client was not built

    build-depends:    base ^>=4.19.1.0,
                      text,
                      transformers,
                      hw-kafka-client
max@nakatomi core % cabal build
Resolving dependencies...
Build profile: -w ghc-9.8.2 -O1
In order, the following will be built (use -v for more details):
 - hw-kafka-client-5.3.0 (lib) (requires build)
 - core-0.1.0.0 (lib) (first run)
 - core-0.1.0.0 (exe:core) (first run)
Starting     hw-kafka-client-5.3.0 (lib)

Failed to build hw-kafka-client-5.3.0. The failure occurred during the
configure step.
Build log ( /Users/max/.cabal/logs/ghc-9.8.2/hw-kfk-clnt-5.3.0-6caa0bcf.log ):
Configuring library for hw-kafka-client-5.3.0..
Error: cabal-3.10.3.0: Missing dependency on a foreign library:
* Missing (or bad) C library: rdkafka
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

Error: cabal: Failed to build hw-kafka-client-5.3.0 (which is required by
exe:core from core-0.1.0.0). See the build log above for details.

What I missed?

Thanks in advance

It seems to me that you have to add this field to you .cabal file (as the error says):

https://cabal.readthedocs.io/en/stable/cabal-package-description-file.html#pkg-field-extra-lib-dirs

thanks for reply

nope, it doesn’t work

    extra-lib-dirs: /opt/homebrew/Cellar/librdkafka/2.6.1/include/librdkafka,
                    /opt/homebrew/Cellar/librdkafka/2.6.1/lib

    extra-lib-dirs-static: /opt/homebrew/Cellar/librdkafka/2.6.1/include/librdkafka,
                           /opt/homebrew/Cellar/librdkafka/2.6.1/lib

I just don’t understand why every time I touch cabal it doesn’t work, why super beautiful language such Haskell has such bad package mechanism

In addition to cabal and stack:

Another option that is mentioned here is Nix.

I don’t think I follow, what is this in response to?

Have you set the extra include dirs as well? I had the same issue like 2 years ago but I don’t remember exactly. I may have needed to add the directory to LD_LIBRARY_PATH and DYLD_LIBRARY_PATH env vars

@mxgr, I believe the root of the problem is a very confusing distinction between local and non-local packages for cabal. Put shortly, command line flags (such as --extra-include-dirs) only apply to local packages.

In your case, when you do cabal install hw-kafka-client, the target hw-kafka-client is considered local, so the command line flags apply.

When you use a cabal file and list hw-kafka-client as a dependency, it is not local. In that case, core is a local package so the flags apply to core, which is not very useful.

What you want is to specify flags for non-local packages. You can do that by creating a cabal.project file in the root of your package with the contents similar to this:

packages: .

package hw-kafka-client
  extra-include-dirs: /opt/homebrew/Cellar/librdkafka/2.6.1/include
  extra-lib-dirs: /opt/homebrew/Cellar/librdkafka/2.6.1/lib

It says to apply those flags to that package.
The ticket in Cabal where people with this problem end up: --extra-lib-dirs and --extra-include-dirs ignored? · Issue #2997 · haskell/cabal · GitHub

1 Like

it works!!! thanks a lot man, I need some time to research your answer and cabal.project itself. thanks!

1 Like