<div><div>Hello, <br></div><div><br></div><div>I want to use a foreign C++ Function in a Haskell Library, and the Library in a Haskell Program.<br></div></div><div>The C++ function is separate in a file and I have a header file. <br></div><div>I made <a rel="nofollow" title="https://github.com/Twonki/HaskellForeingCPPMinimal" target="_blank" href="https://github.com/Twonki/HaskellForeingCPPMinimal">a minimal reproducing repository</a>.<br></div><div><br></div><div>The closes I have found is <a rel="nofollow" title="https://github.com/deech/CPlusPlusBindings" target="_blank" href="https://github.com/deech/CPlusPlusBindings">this repository</a> which wraps the c++ in c and makes a full library, needing a makefile etc. <br></div><div>So while I think I'd get it working like that, it looks to be quite a lot to do for my simple task. <br></div><div><br></div><div>the repository structure looks as follows: <br></div><div><br></div><div>Projekt <br></div><ul><li>cpp-src<br></li><ul><li>some.cpp<br></li><li>some.h<br></li></ul><li>lib-src<br></li><ul><li>CPPLib.hs<br></li></ul><li>program-src<br></li><ul><li>program.hs<br></li></ul><li>project.cabal<br></li></ul><div class="protonmail_signature_block protonmail_signature_block-empty"><div class="protonmail_signature_block-user protonmail_signature_block-empty"><br></div><div class="protonmail_signature_block-proton protonmail_signature_block-empty"><br></div></div><div><br></div><div>And my (currently failing) project.cabal the following: <br></div><div><br></div><div style="color: #333333;background-color: #f7f3e6;font-family: 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback';font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color:rgb(133, 153, 0)">cabal-version:</span><span style="color:rgb(51, 51, 51)"> </span><span style="color:rgb(211, 54, 130)">3.0</span><br></div><div><span style="color:rgb(133, 153, 0)">name:</span><span style="color:rgb(51, 51, 51)"> cpp_lib</span><br></div><div>[...]<br></div><div><span style="color:rgb(51, 51, 51)">library</span><br></div><div><span style="color:rgb(133, 153, 0)">  exposed-modules:</span><span style="color:rgb(51, 51, 51)">   CPPLib</span><br></div><div><span style="color:rgb(133, 153, 0)">  other-extensions:</span><span style="color:rgb(51, 51, 51)">  ForeignFunctionInterface</span><br></div><div><span style="color:rgb(133, 153, 0)">  build-depends:</span><span style="color:rgb(51, 51, 51)">     base</span><br></div><div><span style="color:rgb(133, 153, 0)">  hs-source-dirs:</span><span style="color:rgb(51, 51, 51)">    lib-src</span><br></div><div><span style="color:rgb(133, 153, 0)">  default-language:</span><span style="color:rgb(51, 51, 51)">  Haskell2010</span><br></div><div><span style="color:rgb(133, 153, 0)">  include-dirs:</span><span style="color:rgb(51, 51, 51)">      ./cpp-src</span><br></div><div><span style="color:rgb(133, 153, 0)">  cxx-sources:</span><span style="color:rgb(51, 51, 51)">       ./cpp-src/some.cpp</span><br></div><div><span style="color:rgb(133, 153, 0)">  install-includes:</span><span style="color:rgb(51, 51, 51)">  ./cpp-src/some.h</span><br></div><div><br></div><div><span style="color:rgb(51, 51, 51)">executable </span><span style="color:rgb(5, 92, 163)">CPPApp</span><br></div><div><span style="color:rgb(133, 153, 0)">  main-is:</span><span style="color:rgb(51, 51, 51)">          program.hs</span><br></div><div><span style="color:rgb(133, 153, 0)">  default-language:</span><span style="color:rgb(51, 51, 51)"> Haskell2010</span><br></div><div><span style="color:rgb(133, 153, 0)">  build-depends:</span><span style="color:rgb(51, 51, 51)">    HaskellForeignCPP,</span><br></div><div><span style="color:rgb(51, 51, 51)">                    base</span><br></div><div><span style="color:rgb(133, 153, 0)">  hs-source-dirs:</span><span style="color:rgb(51, 51, 51)">   program-src</span><br></div><div><span style="color:rgb(133, 153, 0)">  </span><br></div></div><div><br></div><div>The some.cpp is trivial for this case lets assume its a function multiply :: Int -> Int -> Int, and both .cpp and .h are well-formed and don't have further dependencies. <br></div><div><br></div><div>The library compiles fine, but when building the executable it fails telling me <br></div><div><br></div><div>collect2: error: ld returned 1 exit status<br></div><div>`gcc' failed in phase `Linker'. (Exit code: 1)<br></div><div><br></div><div>Can someone help me out? <br>I find very little documentation on this topic. </div><div><br></div><div>I know there is Inline-CPP which would help as well, but I just very much like the idea of having a nice separate file and interface for modularity. <br></div><div><br></div><div>best<br></div><div>Leonhard<br></div><div><br></div>