<div dir="ltr"><div>Hi,</div><div><br></div><div>Would it be possible to upload your full repo somewhere so people could see everything and possibly reproduce this?</div><div><br></div><div>Thanks,</div><div><br></div><div>toz</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 25, 2020 at 5:03 AM <<a href="mailto:beginners-request@haskell.org">beginners-request@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send Beginners mailing list submissions to<br>
        <a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:beginners-request@haskell.org" target="_blank">beginners-request@haskell.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:beginners-owner@haskell.org" target="_blank">beginners-owner@haskell.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Beginners digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1.  Linking C++ in Cabal (Leonhard Applis)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sun, 24 May 2020 16:30:22 +0000<br>
From: Leonhard Applis <<a href="mailto:Leonhard.Applis@protonmail.com" target="_blank">Leonhard.Applis@protonmail.com</a>><br>
To: "<a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a>" <<a href="mailto:beginners@haskell.org" target="_blank">beginners@haskell.org</a>><br>
Subject: [Haskell-beginners] Linking C++ in Cabal<br>
Message-ID:<br>
        <51wOfngyX74dYjJRw6hibqw07vGHvvSYPD_f3f2-_F7hG0k0GwWf2Xv4g7LyeZNyn_vR28s6GIbd3e-78_TapNIEo_tJZ-2fTViOmkQYOnM=@<a href="http://protonmail.com" rel="noreferrer" target="_blank">protonmail.com</a>><br>
<br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hello,<br>
<br>
I want to use a foreign C++ Function in a Haskell Library, and the Library in a Haskell Program.<br>
The C++ function is separate in a file and I have a header file. <br>
I made a minimal reproducing repository.<br>
<br>
The closes I have found is this repository which wraps the c++ in c and makes a full library, needing a makefile etc.<br>
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>
<br>
the repository structure looks as follows:<br>
<br>
Projekt<br>
<br>
-   cpp-src<br>
<br>
-   some.cpp<br>
-   some.h<br>
<br>
-   lib-src<br>
<br>
-   CPPLib.hs<br>
<br>
-   program-src<br>
<br>
-   program.hs<br>
<br>
-   project.cabal<br>
<br>
<br>
<br>
And my (currently failing) project.cabal the following:<br>
<br>
cabal-version:  3.0<br>
name: cpp_lib<br>
[...]<br>
library<br>
exposed-modules: CPPLib<br>
other-extensions: ForeignFunctionInterface<br>
build-depends: base<br>
hs-source-dirs: lib-src<br>
default-language: Haskell2010<br>
include-dirs: ./cpp-src<br>
cxx-sources: ./cpp-src/some.cpp<br>
install-includes: ./cpp-src/some.h<br>
<br>
executable CPPApp<br>
main-is: program.hs<br>
default-language: Haskell2010<br>
build-depends: HaskellForeignCPP,<br>
base<br>
hs-source-dirs: program-src<br>
<br>
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>
<br>
The library compiles fine, but when building the executable it fails telling me<br>
<br>
collect2: error: ld returned 1 exit status<br>
`gcc' failed in phase `Linker'. (Exit code: 1)<br>
<br>
Can someone help me out?<br>
I find very little documentation on this topic.<br>
<br>
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>
<br>
best<br>
Leonhard<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.html" rel="noreferrer" target="_blank">http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.html</a>><br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: signature.asc<br>
Type: application/pgp-signature<br>
Size: 477 bytes<br>
Desc: OpenPGP digital signature<br>
URL: <<a href="http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.sig" rel="noreferrer" target="_blank">http://mail.haskell.org/pipermail/beginners/attachments/20200524/9019cbc0/attachment-0001.sig</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br>
<br>
------------------------------<br>
<br>
End of Beginners Digest, Vol 143, Issue 12<br>
******************************************<br>
</blockquote></div></div>