GHCI with transitive dynamic library dependency fails to properly resolve symbols

Hello All!

I am having an issues hopefully someone has been able to solve it. The issue is the following. I am trying to use ghci for interactive development and for this I have created a few modules which reference C code by using FFI. My particular case looks in this way:

libA (C) -> libB (C++) libC (C)
this is installed in my system as:

libA.o, etc...

When I try to compile for example for unit test I can make it work. But the problem is ghci has problems when linking my dynamic libraries.

In particular when running

cabal repl --ghc-options="-L/usr/local/lib -lA -lB -lC -lstdc++"

ghci loads but when referencing an imported function in the interactive session I get the following error:

/home/gserranowong/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/bin/./ghc-9.4.8: symbol lookup error: /usr/local/lib/ undefined symbol: _ZN9CDocumentC1Ev

Here _ZN9CDocumentC1Ev is declared in libA but really defined in libB. So it seems that ghci its trying to load from the wrong library and the name is not correctly resolved. I have check the symbols in libA and libB and this is the case.


Hello! That’s a bit weird

Hello, that’s a bit weird. I’d be happy to help you investigate this if you have a standalone reproducer. Perhaps you could open a ticket in the Cabal issue tracker with the reproducer.