Statically link C++ library with a Haskell library

后端 未结 2 551
夕颜
夕颜 2020-12-15 09:31

Setup: I have a Haskell library HLib which makes calls to a C/C++ backend CLib for efficiency. The backend is small and specialized for use with

2条回答
  •  -上瘾入骨i
    2020-12-15 09:55

    GHC cannot really understand C++ header files. It needs pure C code. The common way for a C++ header file to provide C interface is to isolate away C++ parts with #ifdef __cplusplus, e.g.:

    #ifdef __cplusplus
    extern "C" {         // C compilers and various C-based FFIs don't like this
    #endif
    
    void foo();
    
    #ifdef __cplusplus
    }
    #endif
    

    In addition, GHCi is historically known to have problems with linking C++ code. For example, at one point it didn't understand weak symbols (often produced by the compiler in conjunction with inline functions and template instantiations). You might be seeing one of these problems. I'd recommend filing a bug report to the GHC team.

提交回复
热议问题