小编Yan*_*n.F的帖子

用Cabal从C调用Haskell

我无法弄清楚如何构建一个使用外部函数接口调用Haskell的C SDL应用程序,我的主要是在C中,这是我的.cabal文件:

build-type:          Simple
extra-source-files:  README.md
cabal-version:       >=1.10

library
  exposed-modules:     AI     

  other-extensions:    ForeignFunctionInterface
  build-depends:       base >=4.9 && <4.10
  hs-source-dirs:      src/haskell
  default-language:    Haskell2010
  ghc-options:         -O2 -shared -fPIC -dynamic 
  extra-libraries:     HSrts-ghc8.0.2
Run Code Online (Sandbox Code Playgroud)

我按照此链接中的说明没有成功(它适用于OSX,而​​不是Linux).我正在通过以下方式成功构建Haskell源代码:

cabal install
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何以Haskell被识别并导入C的方式构建C代码.这是我的C和Haskell源代码的示例:

main.c中:

#include <stdio.h>
#include "game.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_error.h>
#include "HsFFI.h" // include path not recognized
#include "AI_stub.h" // new! edited

int main( int argc, char** argv ) {
    hs_init(&argc, &argv);
    //HASKELL CALL
    int i;
    i = fibonacci_hs(42);
    printf("Fibonacci: %d\n", i); …
Run Code Online (Sandbox Code Playgroud)

c haskell cabal

13
推荐指数
1
解决办法
251
查看次数

标签 统计

c ×1

cabal ×1

haskell ×1