作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了以下 C 库来读取图像:
typedef struct {
unsigned int height;
unsigned int width;
unsigned char* red; //length=height*width
unsigned char* green;
unsigned char* blue;
} Contents;
Contents readJPEGFile(const char* inFilename);
我确实找不到任何使用外部函数接口(interface)的数组和结构的信息。我如何才能在 Haskell 中使用我的库?
我尝试使用以下示例作为基础:http://therning.org/magnus/archives/315但随后 hsc 文件被编译为仅包含上述 c 代码的 hs 文件(当然它无法编译)。
最佳答案
基本的 FFI 支持仅包括标量类型。你最终用地址算术做的所有其他事情。 section on foreign types FFI 文档中提供了基础知识,您可以在 FFI Cookbook 中找到示例.
您曾经可以使用 Green Card 等工具和 H/Direct为您生成编码和解码代码。由于我不明白的原因,这些工具已经很长时间没有更新了。据我所知,当前选择的工具是 hsc2hs
。
编辑:如评论中所述(感谢ephemient),c2hs
也很受欢迎,而且由于 c2hs
来自 Manuel Chakravarty,因此它可能会很好。
关于haskell - 如何在结构上使用 Haskell 的 FFI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/670221/
我是一名优秀的程序员,十分优秀!