Re: [Haskell-beginners] Linking C++ in Cabal

Hi,
Would it be possible to upload your full repo somewhere so people could see
everything and possibly reproduce this?
Thanks,
toz
On Mon, May 25, 2020 at 5:03 AM
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-request@haskell.org
You can reach the person managing the list at beginners-owner@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
To: "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
participants (1)
-
鲍凯文