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