Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell cabal include static library

Tags:

haskell

cabal

ffi

I have an embarrassingly simple question.

I am trying to use an archive library (call it mylib.a) with a large'ish C project (compiled with GHC's copy of MinGW).

From the top level I have:

./project.cabal
./src/...haskell..code...
./cbits/interface.c (simplifies access to `lib.a`)
./include/mylib.h
./lib/mylib.a      <<<<<<<<<<<<<<< not sure where to put this or how to reference it

The project.cabal has both

c-sources:           cbits/interface.c
include-dirs:        include

The extra-lib-dirs seems to want an absolute path (directory).

How does one solve this?

like image 889
Tim Avatar asked Oct 19 '22 13:10

Tim


1 Answers

The answer is from here https://github.com/haskell/cabal/issues/4677

I suppose your archive is name libmylib.a, then add this in your cabal file

ghc-Options: -pgml gcc "-optl-Wl,--allow-multiple-definition" "-optl-Wl,--whole-archive" "-optl-Wl,-Bstatic" "-optl-Wl,-lmylib" "-optl-Wl,-Bdynamic" "-optl-Wl,--no-whole-archive"

you might also need to specify the gcc option -L to specify the archive path

like image 83
dfordivam Avatar answered Oct 31 '22 15:10

dfordivam