Tim
Tim

Reputation: 2796

Haskell cabal include static library

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?

Upvotes: 5

Views: 1757

Answers (1)

dfordivam
dfordivam

Reputation: 169

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

Upvotes: 3

Related Questions