Thanks,<br><br>I found on one site how to compile after creating the stub files with GHC:<br><br>First step:<br><b>ghc -c -ffi haskell_file.hs</b><br>Second step - here it is important to know and write where are the ghc libraries:<br>
<b>gcc -I /usr/local/lib/ghc-5.04.3/include -c C_file.c </b><br>After that it is important to link my creted C_file with the stub file and compile it:<br><b>ghc -no-hs-main -o C_file C_file.o haskell_file.o haskell_file_stub.o</b><br>
<br>The final result is C_file execution file...just enter C_file and the program is running correctly.<br><br>This information: how to compile and to link C with Haskell and to call a Haskell funtion from C was quite difficult.<br>
But here is my result of googling throw the internet and to find something usefull.<br><br>Next challange: link C++ with C and creating a usefull documentation and put it online!<br><br>Ciao,<br>Miguel Lordelo.<br><br><br>
<br><br><div class="gmail_quote">On Fri, Apr 18, 2008 at 3:33 PM, Alfonso Acosta &lt;<a href="mailto:alfonso.acosta@gmail.com">alfonso.acosta@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Although you could use gcc to link the code I wouldn&#39;t recommend it<br>
(mainly for the problems you are currently having)<br>
<br>
SImply call GHC to compile both the C and Haskell code. It will take<br>
care of finding the headers and supplying the necessary linker<br>
arguments.<br>
<br>
ghc -ffi -c &nbsp; foo.hs myfoo_c.c<br>
<br>
BTW, you don&#39;t need to compile viaC<br>
<br>
2008/4/17 Miguel Lordelo &lt;<a href="mailto:miguellordelo@gmail.com">miguellordelo@gmail.com</a>&gt;:<br>
<div><div></div><div class="Wj3C7c">&gt; Well Isaac...I became now a little bit smarter then yesterday!!!<br>
&gt;<br>
&gt; I show you the example that I found and on which I´m working with.<br>
&gt;<br>
&gt; File: foo.hs<br>
&gt; module Foo where<br>
&gt;<br>
&gt; foreign export ccall foo :: Int -&gt; IO Int<br>
&gt;<br>
&gt; foo :: Int -&gt; IO Int<br>
&gt; foo n = return (length (f n))<br>
&gt;<br>
&gt; f :: Int -&gt; [Int]<br>
&gt; f 0 = []<br>
&gt; f n = n:(f (n-1))<br>
&gt;<br>
&gt; To get the C wrapper you insert the following command:<br>
&gt; ghc -ffi -fvia-C -C foo.hs<br>
&gt;<br>
&gt; &nbsp;After execution you will have these following additional files:<br>
&gt;<br>
&gt; foo.hc<br>
&gt; foo.hi<br>
&gt; foo_stub.c<br>
&gt; foo_stub.h<br>
&gt; foo_stub.o<br>
&gt;<br>
&gt; What I did next was to create a file named: myfoo_c.c, where I will call the<br>
&gt; foo function (implemented in Haskell).<br>
&gt; &nbsp;(you can see this example on<br>
&gt; <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html" target="_blank">http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html</a> )<br>
&gt; But the problem is to compile with gcc (must I put any flag or whatever set<br>
&gt; something)<br>
&gt;<br>
&gt; The gcc output is:<br>
&gt; myfoo_c.c:2:19: error: HsFFI.h: No such file or directory<br>
&gt;<br>
&gt; I downloaded this header file from: (I know that is not the correct way, but<br>
&gt; it was the only idea that occurs at the moment)<br>
&gt; <a href="http://www.koders.com/c/fidD0593B84C41CA71319BB079EFD0A2C80211C9337.aspx" target="_blank">http://www.koders.com/c/fidD0593B84C41CA71319BB079EFD0A2C80211C9337.aspx</a><br>
&gt;<br>
&gt; I compiled again and the following return error appears:<br>
&gt; myfoo_c.c:(.text+0x1c): undefined reference to `hs_init&#39;<br>
&gt; myfoo_c.c:(.text+0x31): undefined reference to `foo&#39;<br>
&gt; myfoo_c.c:(.text+0x50): undefined reference to `hs_exit&#39;<br>
&gt; &nbsp;collect2: ld returned 1 exit status<br>
&gt;<br>
&gt; These functions are necessary to setup GHC runtime (see:<br>
&gt; <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html" target="_blank">http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html</a> )<br>
&gt;<br>
&gt; What I want to know is how to compile myfoo_c.c?! Is it with GCC or GHC?!<br>
&gt;<br>
&gt; Chears,<br>
&gt; Miguel Lordelo.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Apr 16, 2008 at 9:16 PM, Isaac Dupree &lt;<a href="mailto:isaacdupree@charter.net">isaacdupree@charter.net</a>&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt; &gt; perhaps<br>
&gt; &gt;<br>
&gt; &gt; haskell:<br>
&gt; &gt; foreign export &quot;foo_func&quot; foo :: Int -&gt; IO Int<br>
&gt; &gt; -- I forget the rest of the syntax here<br>
&gt; &gt;<br>
&gt; &gt; C++:<br>
&gt; &gt;<br>
&gt; &gt; extern &quot;C&quot; {<br>
&gt; &gt; int foo_func(int i);<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt; int some_cplusplus_function() {<br>
&gt; &gt; &nbsp;int bat = 3;<br>
&gt; &gt; &nbsp;int blah = foo_func(bat);<br>
&gt; &gt; &nbsp;return blah;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Is that all you need to do?<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Miguel Lordelo wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Hi all,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Well...somehow I&#39;m a beginner in Haskell. But actually my interest in<br>
&gt; &gt; &gt; Haskell will increase if it is possible to call a haskell function in<br>
&gt; C++.<br>
&gt; &gt; &gt; Something like GreenCard ( <a href="http://www.haskell.org/greencard/" target="_blank">http://www.haskell.org/greencard/</a> )<br>
&gt; simplifying<br>
&gt; &gt; &gt; the task of interfacing Haskell programs to external libraries<br>
&gt; (usually).<br>
&gt; &gt; &gt; But is there also a task to interface a foreign language with Haskell,<br>
&gt; but<br>
&gt; &gt; &gt; calling Haskell functions. Or c2hs which is an interface generator that<br>
&gt; &gt; &gt; simplifies the development of Haskell bindings to C libraries.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I want to know this, because in my company some guys are doing some<br>
&gt; testing<br>
&gt; &gt; &gt; with Frotran and MatLab and I want to show them the power of haskell and<br>
&gt; the<br>
&gt; &gt; &gt; software which we are using is implemented in C++ (there is the reason<br>
&gt; to<br>
&gt; &gt; &gt; make Haskel -&gt; C++).<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I read somewhere that the only way for C++ calling a haskell function is<br>
&gt; to<br>
&gt; &gt; &gt; create a binding between Haskell and C and from C to C++, but a easy<br>
&gt; &quot;Hello<br>
&gt; &gt; &gt; World&quot; example was not there.<br>
&gt; &gt; &gt; Unfortunatelly I couldn&#39;t found anything usefull, like an complete<br>
&gt; example,<br>
&gt; &gt; &gt; or how to compile the code from haskell to C to C++.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Can sombody help me, please :P<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Chears,<br>
&gt; &gt; &gt; Miguel Lordelo.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; ------------------------------------------------------------------------<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; Haskell-Cafe mailing list<br>
&gt; &gt; &gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; &gt; &gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; &nbsp;Haskell-Cafe mailing list<br>
&gt; &nbsp;<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; &nbsp;<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>