我所要做的事情: 我试图通过其FFI从Haskell调用C++(通过
请注意我尝试包含
extern "C"{...}
接口)。特别是,我有一个名为three.cpp
的C++文件;它里面有一个被外部引用的C ++函数,我正在尝试从Haskell中访问它(其中一些其他私有C ++代码在后台运行)。
问题: 我可以成功运行stack build
和stack test
,一切都如预期那样工作。然而,当我运行stack ghci
时,我会收到以下错误:/usr/bin/ld: /home//Dropbox/Sling/.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/Sling-exe/Sling-exe-tmp/src/three.o: relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
可能需要的信息: 我项目.cabal
文件中相关部分如下:
executable Sling-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -fPIC -threaded -rtsopts -with-rtsopts=-N
cc-options: -fPIC
extra-libraries: stdc++
build-depends: base
C-sources: src/three.cpp
Include-dirs: include
Includes: include/three.h
Install-includes: three.h
default-language: Haskell2010
请注意我尝试包含
-fPIC
标志,但失败了。有什么建议吗?