我在Haskell中尝试C ++绑定,并在调用绑定时遇到“未定义的引用”错误。
我做了一个小项目(http://github.com/deech/CPlusPlusBindings)来说明问题。它包括一个小的C ++类,一个C包装器,一个C测试脚本和一个Haskell绑定和一个测试脚本。 C测试脚本有效,Haskell给我一个:
[1 of 1] Compiling Binding ( dist/build/Binding.hs, dist/build/Binding.o )
src/Binding.chs:6:26: Warning: Defined but not used: `res'
In-place registering CPlusPlusBinding-0.1.0.0...
Preprocessing executable 'binding_test' for CPlusPlusBinding-0.1.0.0...
[1 of 1] Compiling Main ( src/BindingTest.hs, dist/build/binding_ /binding_test-tmp/Main.o )
src/BindingTest.hs:3:1: Warning:
Top-level binding with no type signature: main :: IO ()
Linking dist/build/binding_test/binding_test ...
../CPlusPlusBinding/c-src/libA_C.a(A_C.o): In function `A_static_function':
../CPlusPlusBinding/c-src/A_C.cpp:4:0:
undefined reference to `A::static_function()'
../CPlusPlusBinding/c-src/libA_C.a(A_C.o): In function `A_member_function':
../CPlusPlusBinding/c-src/A_C.cpp:7:0:
undefined reference to `A::member_function()'
../CPlusPlusBinding/c-src/libA_C.a(A_C.o): In function `A_new':
../CPlusPlusBinding/c-src/A_C.cpp:10:0:
undefined reference to `operator new(unsigned long)'
collect2: error: ld returned 1 exit status
运行cabal configure
和cabal build
将编译C ++和C绑定并重现错误。
更新
我已经解决了下面评论中概述的问题。但是,我似乎无法回答我自己的问题。
答案 0 :(得分:1)
社区维基回答以供将来参考。解决方案是通过更改cabal文件来更改库呈现给链接器的顺序。
include-dirs: ./c-src
ghc-options: -Wall -threaded -lHSCPlusPlusBinding-0.1.0.0 -lA_C -lA -lstdc++