<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<br><br>I'm trying to get a toy, loadable C++ library compiled.  My setup is 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>I'm using the latest tarball of gambit, compiled with --enable-cplusplus.<br><br>I compile foo.scm to C++ via:<br><br>gsc -link -flat foo.scm ==> foo.c and foo_.c<br><br>Then I want to compile these into <span style="border-bottom: 1px dashed rgb(0, 102, 204); cursor: pointer;" class="yshortcuts" id="lw_1235482845_0">object files</span> and I run into trouble.   g++ -fPIC -c foo.c outputs the following:<br><br>oo.c: In function ‘int ___H__20_foo_23_0(___processor_state_struct*)’:<br>foo.c:119: error: ‘cpp_bar’ was not declared in this
 scope<br>foo.c: At global scope:<br>foo.c:156: warning: deprecated conversion from string constant to ‘char*’<br><br>Whereas

gcc compiles it fine.  It must be a name-mangling issue, but it seems
peculiar to me, given that I compiled gsc using g++.  Moreover, I can
compile if I add extern "C" {int cpp_bar(char*);} to foo.c.  I picked
this up from reading about someone who had similar problems a few years
ago:<br><br><a target="_blank" href="http://osdir.com/ml/lisp.scheme.gambit/2005-02/msg00037.html"><span class="yshortcuts" id="lw_1235482845_1">http://osdir.com/ml/lisp.scheme.gambit/2005-02/msg00037.html</span></a><br><br>I then compile and link like:<br><br>g++ -fPIC -c -D___DYNAMIC foo_.c foo.c<br>g++ -fPIC -c -D___DYNAMIC foo.cpp -o cppfoo.o<br>ld -G -o foo.o1 /usr/lib/libstdc++.so.6.0.9 /usr/lib/gcc/i486-linux-gnu/4.2/crtbegin.o cppfoo.o foo_.o foo.o<br><br>Unfortunately, this leads me here:<br><br>*** WARNING -- Could not find C function: "____20_foo_2e_o1"<br>*** ERROR IN ##main -- .../foo.o1: undefined symbol: cpp_bar<br>(load "foo.o1")<br><br>Can anyone offer me any pointers on how to proceed?<br><br>-John</td></tr></table><br>