Including C ++ sources in a Haskell project

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

I know that he is doing something with a C ++ file because it does not compile if there are errors.

I still need to try to start the project, because it is a library and still has nothing runnable, but repl does not seem to work.

When I try to run it ( stack repl in this case), I get a missing character error with some malformed name that may or may not refer to the name in my file.

 unknown symbol `_ZdlPv' linking extra libraries/objects failed 

How can I fix this problem? I had a similar problem before I fixed it manually by compiling the source code into a dynamic library and then using this library in my project. I do not want to do this because it connects me with the platform, and since it makes no sense that simple C ++ cannot be compiled with the project using tools that GHC already has. I want this to be hackable.

Is there something I am missing? If not, is this a mistake, and are there any plans to fix it?

+5
source share
1 answer

Ok, I managed to “fix” it now.

I added extra-libraries: stdc++-6, gcc_s_seh-1 to my cabal file, and now it works. I don't know if this is platform independent, but these libraries come with GHC when I install it through the stack.

+2
source

All Articles