<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Marc,<br>
<br>
Thanks for the response.  The include did indeed solve my compilation problems. <br><br>Now I'm compiling like this:<br><br>gsc -link -flat foo.scm<br>g++ -Wno-write-strings -fPIC -c -D___DYNAMIC foo_.c foo.c<br>g++ -Wno-write-strings -fPIC -c -D___DYNAMIC foo.cpp -o cppfoo.o<br>ld -G -o foo.o1 cppfoo.o foo.o foo_.o<br><br>This leads to a run-time linking error of:<br><br>*** WARNING -- Could not find C function: "____20_foo_2e_o1"<br>*** ERROR IN ##main -- .../foo.o1: undefined symbol: ____20_foo_2e_o1<br>(load "foo.o1")<br><br>Any idea what the issue is here?<br><br>-John<br><br><br>--- On <b>Tue, 2/24/09, Marc Feeley <i><feeley@iro.umontreal.ca></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">From: Marc Feeley <feeley@iro.umontreal.ca><br>Subject: Re: [gambit-list] Difficulties linking against a C++ library<br>To: bargarply@yahoo.com<br>Cc:
 gambit-list@iro.umontreal.ca<br>Date: Tuesday, February 24, 2009, 2:22 PM<br><br><pre>On 24-Feb-09, at 8:41 AM, John Thompson wrote:<br><br>> Hi,<br>> <br>> I'm trying to get a toy, loadable C++ library compiled.  My setup is<br>as follows:<br>> <br>> foo.scm:<br>> <br>>  (define bar (c-lambda (char-string) int "cpp_bar"))<br>> <br>> foo.cpp:<br>> <br>> int cpp_bar(char* text) {<br>>   return 0;<br>> }<br>> <br>> foo.h:<br>> <br>> int cpp_bar(char* text);<br><br>In C++, prototypes are not optional (and if it works in C it is by accident). <br>In the C++ code generated for foo.scm the C++ compiler has no idea what is the<br>prototype of cpp_bar that you want to call.  You might think that the c-lambda<br>types are there to supply that information, but in fact the Gambit compiler<br>simply generates a call to cpp_bar whose *actual* parameters are those of the<br>c-lambda.  By not automatically generating
 a prototype for cpp_bar it allows for<br>cpp_bar to be a macro or a qualified name such as "cpp::bar" or inline<br>code such as "___result = ___arg1[0];".  So to solve your problem<br>foo.scm should be<br><br>(c-declare #<<end-of-c-declare<br>#include "foo.h"<br>end-of-c-declare<br>)<br><br>(define bar (c-lambda (char-string) int "cpp_bar"))<br><br>Note that you'd have to include foo.h if this was a C++ module, for exactly<br>the same reasons, so it shouldn't be too surprising.<br><br>Marc<br><br></pre></blockquote></td></tr></table><br>