Using a C ++ library (boost) with inline-c-cpp

In Haskell, I would like to call a function from an enhance C ++ library using inline-c-cpp .

After loading the library boost

, how do I set up the file cabal

and fields in extra-lib-dirs

and extra-include-dirs

out stack.yaml

?

In the file cabal

I write:, extra-libraries: boost

and I tried several folders in extra-lib-dirs

and extra-include-dirs

, but I always get Missing C library: boost

.

Edit

This is my attempt after @nm comments. In stack.yaml

:

extra-include-dirs:
- U:\Data\C\boost_1_64_0

      

In the cabal file:

  extra-libraries:     stdc++
  c-sources:           src/Main.cpp

      

My module:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ForeignFunctionInterface #-}

module Main
  where
import qualified Language.C.Inline.Cpp as C

C.context C.cppCtx

C.include "<iostream>"
C.include "<boost/math/special_functions/owens_t.hpp>"

main :: C.CDouble -> C.CDouble -> IO ()
main h a = do
  [C.block| void {
      std::cout << "Hello, Owen! " << boost::math::owens_t($(double h), $(double a)) << std::endl;
    } |]

      

Compilation of the code without problems. However, when I run main 1 1

in GHCi

, I get the error

ghc.exe: C:\HaskellProjects\inlinecpp\.stack-work\install\e77882c1\lib\x86_64-windows-ghc-8.0.2\inlinecpp-0.1.0.0-IWaed3tDnUhE52nToDO1Sq\HSinlinecpp-0.1.0.0-IWaed3tDnUhE52nToDO1Sq.o: unknown symbol `_Unwind_Resume'

      

Edit

This works if I make and run an executable. But I would like to use it in GHCi.

+3


source to share


1 answer


The code posted in Edit works in GHCi with ghc 8.2.1

.



Prelude Main> main 0.5 0.5
Hello, Owen! 0.0644886

      

0


source







All Articles