[Haskell-cafe] c2hs: E.g. #include <iostream> OK in *.cpp's, but not in *.h's

Nick Rudnick nick.rudnick at gmail.com
Sun Apr 6 18:22:44 UTC 2014

Dear all,

maybe this is a piece of c2hs behaviour I missed to understand, but it
appears happening with C++ style includes deep in the header call hierarchy
– in case of a such backend C++ library, if one wishes to refer to by *.h's
in c2hs (e.g. for access to types of it), one might have a problem.

- 8< cSample.h ---------------------------------------------
#include <iostream> ///////// here, with c2hs, leading to build abort
#ifdef __cplusplus
extern "C" {
void sampleFunction();
#ifdef __cplusplus
- 8< cSample.cpp ---------------------------------------------
#include "cSample.h"
#include <iostream> ///////// here no problem

void sampleFunction(){
  std::cout << "OK" << std::endl;
- 8< ----------------------------------------------------------------

While 'old school' FFI (foreign import ccall) handles this effortlessly,
c2hs uses to abort with an exception like
C/cSample.h:3:20: fatal error: iostream: No such file or directory
compilation terminated.

I see that hsqml gets around this, but apparently by tweaking Setup.hs in a
way not quite trivial – would this be necessary in any case, or are there
simpler alternatives?

Please excuse if I oversaw something, but I am afraid I didn't see this
interesting issue covered elsewhere.

Thank you a lot in advance & cheers, Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140406/3e165327/attachment.html>

More information about the Haskell-Cafe mailing list