<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Nick Rudnick</b> <span dir="ltr"><<a href="mailto:nick.rudnick@gmail.com">nick.rudnick@gmail.com</a>></span><br>
Date: 2014-04-07 15:28 GMT+02:00<br>Subject: Re: [Haskell-cafe] c2hs: E.g. #include <iostream> OK in *.cpp's, but not in *.h's<br>To: Ian Ross <<a href="mailto:ian@skybluetrades.net">ian@skybluetrades.net</a>><br>
<br><br><div dir="ltr">Hi Ian,<div><br></div><div>thanks for clearing up :-)</div><div><br></div><div>So you mean the trick of hsqml primarily is</div><div><br></div><div>(A) dummy typedefs to char, e.g.:</div><div><br></div>
<div>
typedef char HsQMLStringHandle;<br></div><div><br></div><div>(B) 'extern' sigantures, e.g.:</div><div>extern void hsqml_init_string(HsQMLStringHandle*);<br></div><div><br></div><div>THIS WORKS...</div><div><br></div>

<div>Occasionally, one might use two headers, e.g. a *.hpp as actual C++ header neither listed in the *.cabal nor the *.chs, where instead it would be represented by a *.h, as described above.</div><div><br></div><div>No more...??</div>

<div><br></div><div>Thanks and cheers, Nick</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-07 14:04 GMT+02:00 Ian Ross <span dir="ltr"><<a href="mailto:ian@skybluetrades.net" target="_blank">ian@skybluetrades.net</a>></span>:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Nick,<div><br></div><div>As far as I can tell from a quick look at hsqml, the stuff in Setup.hs isn't related to C2HS.  What's more relevant is that hsqml defines a C library wrapper around the C++ library it uses -- C2HS is only used on that C wrapper, not on the C++ library itself.  In general, C2HS doesn't support C++ at all, because it needs to be able to parse the header files that it includes and we use the C parser from the languagge-c package to do that.  Any C++ constructs will just cause breakage.  And your "old school" FFI definition doesn't look in any header files, which is why it has no trouble.</div>


<div><br></div><div>Basically, if you want to do something like what hsqml does, just take a look in the cbits directory there, in particular at hsqml.h which is the header that defines the C wrapper around the C++ library.  This hsqml.h header is the one that's included in the C2HS files.  If you want to wrap a C++ library directly, C2HS probably isn't the tool for the job.  I know there was some work during the last GSOC on a C++ FFI wrapper, but I don't know if anything concrete came of it.</div>


<div><br></div><div>Cheers,</div><div><br></div><div>Ian.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On 6 April 2014 20:22, Nick Rudnick <span dir="ltr"><<a href="mailto:nick.rudnick@gmail.com" target="_blank">nick.rudnick@gmail.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Dear all,<div><br></div><div>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.</div>



<div><br></div><div>- 8< cSample.h ---------------------------------------------</div><div>#include <iostream> ///////// here, with c2hs, leading to build abort<br></div><div>#ifdef __cplusplus<br></div><div>extern "C" {</div>



<div>#endif</div><div>void sampleFunction();</div><div>#ifdef __cplusplus</div><div>}</div><div>#endif</div>- 8< cSample.cpp ---------------------------------------------<div><div>#include "cSample.h" </div>


<div>
#include <iostream> ///////// here no problem</div><div><br></div><div>void sampleFunction(){ </div><div>  std::cout << "OK" << std::endl;</div><div>}</div>- 8< ----------------------------------------------------------------<div>



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



<div>compilation terminated.</div></div><div><br></div><div>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?</div>



<div><br></div><div>Please excuse if I oversaw something, but I am afraid I didn't see this interesting issue covered elsewhere.</div><div><br></div><div>Thank you a lot in advance & cheers, Nick</div><div><br></div>



<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div>
<br></div></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Ian Ross   Tel: <a href="tel:%2B43%280%296804451378" value="+436804451378" target="_blank">+43(0)6804451378</a>   <a href="mailto:ian@skybluetrades.net" target="_blank">ian@skybluetrades.net</a>   <a href="http://www.skybluetrades.net" target="_blank">www.skybluetrades.net</a>
</font></span></div>
</blockquote></div></div></div><br></div>
</div><br></div>