尝试一个C ++绑定哈斯克尔:让未定义引用错误 [英] Attempting a C++ binding to Haskell: getting undefined reference errors
问题描述
我试图在C ++中哈斯克尔绑定和调用绑定。
I am attempting a C++ binding in Haskell and running into "undefined reference" errors when calling the binding.
我就使一个小项目( http://github.com/deech/CPlusPlusBindings )来说明这个问题。它包括一个小的C ++类,C包装,一个C测试脚本和一个Haskell绑定和测试脚本。在C测试脚本工作,Haskell的人给我:
I've make a small project (http://github.com/deech/CPlusPlusBindings) to illustrate the problem. It includes a small C++ class, a C wrapper, a C test script and a Haskell binding and a test script. The C test script works, the Haskell one gives me:
[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
运行小集团配置
和阴谋构建
将编译C ++和C绑定和重现错误。
Running cabal configure
, and cabal build
will compile the C++ and C bindings and reproduce the error.
更新
在下面的评论概括我已经解决了这个问题。看来我不能回答我的问题,虽然。
I've solved the problem as outlined in the comment below. It appears I can't answer my own question, though.
推荐答案
社区维基答案以供将来参考。解决的办法是,通过改变小集团文件像这样改变图书馆是psented到链接器$ P $的顺序。
community-wiki answer for future reference. The solution was to change the order the libraries were presented to the linker, by altering the cabal file like so.
include-dirs: ./c-src
ghc-options: -Wall -threaded -lHSCPlusPlusBinding-0.1.0.0 -lA_C -lA -lstdc++
这篇关于尝试一个C ++绑定哈斯克尔:让未定义引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!