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