Hsc2hs c ++ headers

I am trying to create a Haskell executable with FFI for some C ++ sources.

I have a C header (cstuff / foo.h) as follows:

#ifndef _FOO_H_
#define _FOO_H_

#include <somecppheader.c> // Some header outside of my control with C++ constructs

void foo();

#endif

The implementation of foo should not matter. It does something and uses something declared in somecppheader.h along the way.

The section of the executable in the Cabal file is as follows:

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

Main.hsc looks something like this:

{-# LANGUAGE ForeignFunctionInterface #-}

#include <foo.h>
foreign import ccall "foo.h foo" :: IO ()

main = foo >> putStrLn "Called foo."

hsc2hs is not really needed in this example, it was just used to run the error I'm trying to describe.

The problem is that somecppheader.h is a C ++ header with C ++ specific constructs, and the inclusion of foo.h seems to compile it as a C header that fails due to C ++ constructs such as definitions classes.

hsc2hs Cabal, foo.h g++, gcc?

+4

Source: https://habr.com/ru/post/1606143/


All Articles