FFI Bindings to Libraries using GMP
simonpj at microsoft.com
Tue Sep 11 03:08:47 EDT 2007
| I've been struggling using FFI bindings to libraries which rely on the
| GNU Mp Bignum library (gmp) - this is apparently a well known problem
| I do rely on using such libraries, and so started to get it work on
| MacOsX; no solution was close to being satisfactory however, so I'd like
| to ask for some advice.
It's an issue that bites very few users, but it bites them hard. It's also tricky, but not impossible, to fix. The combination keeps meaning that at GHC HQ we work on things that affect more people. I doubt we can spare effort to design and implement a fix in the near future -- we keep hoping someone else step up and tackle it!
Peter Tanski did exactly that (he's the author of the ReplacingGMPNotes above), but he's been very quiet recently. I don't know where he is up to. Perhaps someone else would like to join in?
Meanwhile I've added your comments to #311 so they stay with the ticket.
| Those two options worked to some extend:
| Create or modify the library in question, so gmp is statically linked
| and its symbols are hidden.
| When source code is available, this is relatively easy, altough it
| requires modification of the build process (which can be a hassle). If a
| static "ar" archive is available, it is cumbersome (at least on Mac Os X
| I ran into a lot of troubles using nmedit), but possible. Furthermore,
| the resulting libraries are bloated, as each of them contains a copy of
| the GMP; left alone portability issues.
| As suggested in ticket#311, I tried switching the allocator functions
| when switching to FFI. It worked, but not in GHCi; also, doing it
| manually is a lot of work, because, as far as I could figure out, it is
| neccessary to write a wrapper function for every C-function (indirectly)
| using the gmp.
| Furthermore, most of the libraries expose gmp datatypes (mpz_t,mpq_t) in
| their API. I currently use a little haskell module working on
| GHC.Exts, but that's propably not a good option from a maintainer's
| point of view. There are certainly other possibilities, but I couldn't
| find one which is both maintainable and portable.
| I would be very grateful for any advice, or some information on plans
| for resolving ticket #311. There are some great libraries (like the
| Parma Polyhedral Library, to pick an example) out there using gmp, and
| it would be nice if writing bindings to those libs could be simplified.
| Benedikt Huber
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users