Kri*_*itz 5 c++ haskell ffi cabal hsc2hs
我正在尝试针对某些 C++ 源构建带有 FFI 的 Haskell 可执行文件。
我有一个像这样的 C 头文件 (cstuff/foo.h):
#ifndef _FOO_H_
#define _FOO_H_
#include <somecppheader.c> // Some header outside of my control with C++ constructs
void foo();
#endif
Run Code Online (Sandbox Code Playgroud)
foo 的实现应该无关紧要。它会做一些事情并使用一些在 somecppheader.h 中声明的东西。
Cabal 文件中的可执行部分如下所示:
executable botprog
main-is: Main.hsc
other-extensions: ForeignFunctionInterface
build-depends: base >=4.7 && <4.8
build-tools: hsc2hs
default-language: Haskell2010
include-dirs: cstuff
c-sources: cstuff/foo.cpp
pkgconfig-depends: somelib -- The one that contains somecppheader.h
Run Code Online (Sandbox Code Playgroud)
Main.hsc 看起来像这样:
{-# LANGUAGE ForeignFunctionInterface #-}
#include <foo.h>
foreign import ccall "foo.h foo" :: IO ()
main = foo >> putStrLn "Called foo."
Run Code Online (Sandbox Code Playgroud)
在这个例子中实际上并不需要 hsc2hs,它只是用来触发我试图描述的错误。
问题是 somecppheader.h 是具有 C++ 特定构造的 C++ 头文件,而 foo.h 的包含似乎将其编译为 C 头文件,但由于 C++ 构造(如类定义)而失败。
我如何告诉 hsc2hs 或 Cabal foo.h 需要用 g++ 编译,而不是 gcc?