Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linking extra libraries/objects failed

Tags:

haskell

ghci

ffi

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.

like image 418
comatose Avatar asked Nov 13 '22 11:11

comatose


1 Answers

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/

like image 71
garrett mitchener Avatar answered Dec 25 '22 17:12

garrett mitchener