I made FFI bindings to C++ unordered_map(a.k.a. hash_map) container and its wrapper library called libstl.a.
At the first time, it used to work well. But after some point, it has failed to link the library with the following error messages and I can't figure out why.
$ ghci -L. -lstl -lstdc++
GHCi, version 7.6.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading object (static archive) ./libstl.a ... done
Loading object (dynamic) /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so ... done
final link ... ghc: ./libstl.a: unknown symbol `_ZZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEmE10__fast_bkt'
linking extra libraries/objects failed
Source codes for the library is located in https://github.com/comatose/stl-container. Any help will be appreciated.
I've had similar problems loading .o files into ghci. From what I understand, the problem is that g++ leaves 'weak symbols' in .o files, and ghci doesn't deal with them very well.
I found a thread about it with a helpful follow-up:
http://www.haskell.org/pipermail/haskell-cafe/2012-March/099926.html
in which the suggested solution is to put everything compiled by g++ into shared libraries (.so files instead of .a), and that seems to clear up the weak symbol problem. Shared libraries can be a bit of a pain. I suggest that you look at libtool. It's a helper program that can handle a lot of the complications:
http://www.gnu.org/software/libtool/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With