Sorry for the double post, but I forgot to mention I&#39;m using GHC 7.4 and gcc/libstdc++ 4.5.2.<br>(Running Ubuntu 11.04 Natty Narwhal).<br><br><div class="gmail_quote">2012/3/7 Yves Parès <span dir="ltr">&lt;<a href="mailto:yves.pares@gmail.com">yves.pares@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, I&#39;m trying to have GHCi load a haskell file that depends on a C++ object file, which causes GHCi to fail because of an unknown symbol (<b>and I did link with </b><b>libstdc++</b>), whereas the link into an executable with ghc works and runs perfectly.<br>


<br>I&#39;ve reduced my code to the smallest one that produces the problem:<br>The C++ part defines a mere class and C externals that enable communication with Haskell:<br><br>// Header Stuff.hpp<br><span style="font-family:courier new,monospace">class Base {</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    public:</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">        Base();</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">        ~Base();</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">extern &quot;C&quot; {</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    Base* mkthing();   </span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    void delthing(Base*);</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">}</span><br><br>-----------<br><br>// Source Stuff.cpp<br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">#include &lt;iostream&gt;<br>#include &quot;Stuff.hpp&quot;<br>using namespace std;</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">Base::Base()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    cout &lt;&lt; &quot;Base created&quot; &lt;&lt; endl;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">Base::~Base()</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    cout &lt;&lt; &quot;Base deleted&quot; &lt;&lt; endl;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">extern &quot;C&quot; {</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    Base* mkthing()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    {</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">        return new Base();</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    }</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    void delthing(Base* b)</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    {</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">        delete b;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">    }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">}</span><br><br>Haskell code (just for reference, but I&#39;m not sure it&#39;s relevant), Main.hs:<br>


<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">{-# LANGUAGE ForeignFunctionInterface #-}</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">import Foreign</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">import Foreign.C</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">foreign import ccall unsafe &quot;mkthing&quot;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">  mkthing :: IO (Ptr ())</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">foreign import ccall unsafe &quot;delthing&quot;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">  delthing :: Ptr () -&gt; IO ()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  </span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">main = do</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  p &lt;- mkthing</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">  delthing p</span><br><br><br>I then compile it with:<br>g++ -c Stuff.cpp<br>ghci Main.hs Stuff.o -lstdc++<br><br>And then the error is:<br><span style="font-family:courier new,monospace">Loading object (static) Stuff.o ... done</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">Loading object (dynamic) /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/libstdc++.so ... done</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">final link ... ghc: Stuff.o: unknown symbol `__dso_handle&#39;</span><br style="font-family:courier new,monospace">


<span style="font-family:courier new,monospace">linking extra libraries/objects failed</span><br><br>Whereas &#39;ghc Main.hs Stuff.o -lstdc++&#39; works just fine.<br>Does GHCi lacks a link directive that regular GHC has?<br>


</blockquote></div><br>