[fpc-pascal] Re: Automatically exporting C++ API using SWIG??

Reinier Olislagers reinierolislagers at gmail.com
Sat Oct 20 07:59:55 CEST 2012

On 19-6-2012 9:51, Reinier Olislagers wrote:
> The recent thread about using C headers made me think about using C++
> projects.
> Found that the SWIG tool converts C/C++ .h files into glue code and
> bindings for e.g. Python, Modula 3... but not Delphi/Object Pascal.
> It seems you get an object-oriented binding.
> Did see this post from 2010 about Delphi support:
> http://stackoverflow.com/questions/2559995/create-an-instance-of-an-exported-c-class-from-delphi
>> I've written a SWIG module targetting ObjectPascal and I'm using it
>> successfully in my own project. I've traslated GEOS, and GDAL/OGR
>> library. I also have a branch in the SWIG repository, BUT I still
>> have to complete the final steps to build all the test suites and to
>> fixup the typemaps in order to have the module be accepted.
> ... in a quick browse, couldn't find that branch though.
> (Note: the poster's mail address is mentioned in that post)
> Perhaps this could be useful for somebody interested in this/needing
> this kind of functionality.

Found the code and a discussion on the swig mailing list:

The patches:
The patch.zip includes some documentaton in html format; it e.g.
indicates the code creates (what SWIG calls) proxy classes in Pascal for
C++ classes.
Couldn't find the branch in the SWIG repository mentioned in the post
above, but haven't looked lately.

Good news: the code in question is written to support FPC in Delphi mode:

It has been used to create a Delphi binding for GDAL:

Bad news: it hasn't been committed to SWIG trunk, and is fairly old
(swig 1.3.35), but may well be revived (don't know).

Perhaps this could help somebody and... perhaps we might even see this
in SWIG trunk some day.


More information about the fpc-pascal mailing list