Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including C++ sources in a Haskell project

Tags:

c++

haskell

cabal

I'm trying to make a data structure that will be exposed in Haskell, but implemented in C++. So far I've implemented it in a .cpp file, declared all the functions I need as extern "C" and added the source file to the c-sources field in the .cabal file. When I build the project (in this case with stack build) it seems to build fine.

I know it's doing something to the C++ file because it doesn't compile if there are errors.

I've yet to try running the project because it's a library and so far it doesn't have anything "runnable" written, but the repl doesn't seem to work.

When I try running it (stack repl in this case) I get a missing symbol error with some mangled name that may or may not be refer to a name in my file.

unknown symbol `_ZdlPv'
linking extra libraries/objects failed

How can I fix this issue? I've had a similar problem before that I fixed by manually compiling the source into a dynamic library and then use that library in my project. I don't want to do that since it ties me to a platform and since it makes no sense that a simple C++ couldn't be compiled with the project using the tools that GHC already has. I want to be able to put this on hackage.

Is there something I'm missing? If not, is it a bug and are there plans on fixing it?

like image 554
Luka Horvat Avatar asked Oct 31 '22 04:10

Luka Horvat


1 Answers

Ok, I've managed to "fix" this for now.

I added a extra-libraries: stdc++-6, gcc_s_seh-1 to my cabal file and now it works. No idea if this is platform independant but those libraries do get shipped with GHC when I install it through stack.

like image 59
Luka Horvat Avatar answered Nov 02 '22 11:11

Luka Horvat