[plt-scheme] Using the Foreign Language Interface.

From: Thomas Chust (chust at web.de)
Date: Wed Dec 10 22:39:50 EST 2008

Am 11.12.2008 2:03 Uhr, schrieb Eli Barzilay:
> On Dec 10, Zukowski, Steven D wrote:
>> I'm having issues with the Foreign Language Libraries and using them
>> to get at some C++ functions.
>
> The short answer is that you can't.  C++ libraries use mangled names
> and other tweaks that make interfacing them from Scheme very
> difficult,
> [...]

... which is precisely the reason why every decent C++ compiler supports 
extern "C" declarations to switch off the name magling and export the 
symbols just like a plain C compiler would and usually issue warnings or 
errors if those functions try to use any fancy, C-incompatible features 
of C++.

Just add the following to your header file for functions that have to be 
called from the outside world:

#ifdef __cplusplus
extern "C" {
#endif

   /* Your declarations go here */

#ifdef __cplusplus
}
#endif

Interfacing to object oriented C++ code is a different story, though, 
and is usually not possible at all without writing some wrapper code. If 
you also want cross language exception handling or even cross language 
inheritance hierarchies, the amount of auxiliary code needed will 
probably exceed the amount of actual program logic, but using some 
automatic binding tool like SWIG you can generate it automatically ;-)

cu,
Thomas


Posted on the users mailing list.