cabal:使用-dynamic和共享库构建ghc

时间:2018-06-06 03:21:50

标签: haskell cabal ffi

我正在尝试使用GHC构建动态应用程序,这是我的cabal文件:

executable app
  main-is: Main.hs
  c-sources: cbits/foo.cpp
  cc-options: -shared -fPIC
  include-dirs: /usr/local/lib/llvm-6.0/include
  extra-libraries: stdc++ clang
  extra-lib-dirs: /usr/local/lib/llvm-6.0/lib
  other-modules:
    ...

我需要使用FFI而且我正在使用MacOS。我收到链接器错误:

  

架构x86_64的未定义符号:“_ clangToJSON”,   引自:         CParser.o中的_ClangziCParser_hppTree_info

这确实是我正在尝试访问的外部函数,我在Makefile中使用以下ghc参数获得了成功:

构建FFI impl,共享库:

 clang -fPIC -shared foo.cpp -o foo.so

使用共享库foo.so构建Main.hs:

ghc -dynamic Main.hs -o  -lfoo -L. -optl-Wl,-rpath,'$ORIGIN' 

我设法使用dynamic--enable-shared模式运行cabal但是我需要让cabal中的clang生成一个.so。我正在寻找 dist/build/app我找不到.so,即使我-shared添加了cc-options选项也是如此。如何生成.so然后让cabal动态链接它?

0 个答案:

没有答案