Working around conflict between `c-source` name and GHC RTS name

48 views Asked by At

I have some C source code that I am calling from Haskell using ccall FFI. To make the build process as easy as possible, I'd like to use Cabal to compile the C files, so I've added the sources to the c-sources section of my .cabal file.

The problem is that the C functions that I'm importing into Haskell are implemented in terms of another C function (that I am not directly using from Haskell) called allocate, and that leads to a conflict at link time:

ratkai> [16 of 16] Linking .stack-work/dist/x86_64-linux/Cabal-3.8.1.0/build/ratkai-tvc/ratkai-tvc [Objects changed]
ratkai> /usr/bin/ld.gold: error: /home/cactus/.ghcup/ghc/9.4.5/lib/ghc-9.4.5/lib/../lib/x86_64-linux-ghc-9.4.5/rts-1.0.2/libHSrts-1.0.2.a(Storage.o): multiple definition of 'allocate'
ratkai> /usr/bin/ld.gold: .stack-work/dist/x86_64-linux/Cabal-3.8.1.0/build/ratkai-tvc/ratkai-tvc-tmp/import/ZX0/src/memory.o: previous definition here
ratkai> collect2: error: ld returned 1 exit status
ratkai> ghc-9.4.5: `gcc' failed in phase `Linker'. (Exit code: 1)

Is there a way to work around this without patching the imported C library to rename its allocate function?

0

There are 0 answers