Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Linking C++ in Cabal (Leonhard Applis) ---------------------------------------------------------------------- Message: 1 Date: Sun, 24 May 2020 16:30:22 +0000 From: Leonhard Applis <leonhard.app...@protonmail.com> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] Linking C++ in Cabal Message-ID: <51wOfngyX74dYjJRw6hibqw07vGHvvSYPD_f3f2-_F7hG0k0GwWf2Xv4g7LyeZNyn_vR28s6GIbd3e-78_TapNIEo_tJZ-2fTViOmkQYOnM=@protonmail.com> Content-Type: text/plain; charset="utf-8" Hello, I want to use a foreign C++ Function in a Haskell Library, and the Library in a Haskell Program. The C++ function is separate in a file and I have a header file. I made a minimal reproducing repository. The closes I have found is this repository which wraps the c++ in c and makes a full library, needing a makefile etc. So while I think I'd get it working like that, it looks to be quite a lot to do for my simple task. the repository structure looks as follows: Projekt - cpp-src - some.cpp - some.h - lib-src - CPPLib.hs - program-src - program.hs - project.cabal And my (currently failing) project.cabal the following: cabal-version: 3.0 name: cpp_lib [...] library exposed-modules: CPPLib other-extensions: ForeignFunctionInterface build-depends: base hs-source-dirs: lib-src default-language: Haskell2010 include-dirs: ./cpp-src cxx-sources: ./cpp-src/some.cpp install-includes: ./cpp-src/some.h executable CPPApp main-is: program.hs default-language: Haskell2010 build-depends: HaskellForeignCPP, base hs-source-dirs: program-src 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. The library compiles fine, but when building the executable it fails telling me collect2: error: ld returned 1 exit status `gcc' failed in phase `Linker'. (Exit code: 1) Can someone help me out? I find very little documentation on this topic. 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. best Leonhard -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 477 bytes Desc: OpenPGP digital signature URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.sig> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 143, Issue 12 ******************************************