SWIG

From Free Pascal wiki
Jump to: navigation, search

Overview

SWIG is a program that takes C++ .h and .cpp files and generates object-oriented language bindings for various languages.

Object Pascal support

The main SWIG tree does not support Delphi/Object Pascal.

Some years ago, Stefano Moratti wrote a Delphi adapter for the SWIG code which allows automatic translation of C++ libraries into Delphi mode Object Pascal. [1] His patches were not integrated into mainstream SWIG, but they have been used, e.g. to create a Delphi binding for GDAL: [2]

In 2012, FPC mailing list user d.l.i.w. adapted the original Delphi patches to the more recent SWIG 2.0.8 source but unfortunately forgot to do it in a version-controlled repository. See here: [3] and more about functionality: [4]

Unfortunately, there have been no further efforts to incorporate this into current SWIG trunk. Additionally, FPC developers have indicated that they prefer C++ binding support to bein FPC itself but no work is being done on this currently.

UPDATE 2017: There is a SWIG 3.0.11 for Delphi and Object Pascal: [5]

Download source

The complete set of 2.0.8 files is uploaded at [6] and [7].

An on going effort of 3.0.11 files [8] and [9].

Compiling

In the configure step, it doesn't hurt to specify
--with-delphi=yes
, to indicate you want support for Object Pascal.

On Linux, do e.g. this (run on Debian Linux; adjust paths etc as necessary:

su -
aptitude -y install build-essential yodl byacc mercurial
# build-essential has compilers
# yodl needed for man page install
# byacc apparently needed at least on Debian x86
# mercurial needed to get the swig sources from the bitbucket repository
# alternatively download, extract etc
exit #to regular user, called pascaldev on this system
 
cd ~
hg clone https://bitbucket.org/reiniero/swigdelphi
cd ~/swigdelphi/swig-2.0.8
 
# configure:
chmod ug+rx configure
# tell it to install in user's home directory; adjust as necessary
mkdir ~/swig
./configure --with-delphi=yes --prefix=/home/pascaldev/swig
 
#compile:
make
 
#install:
chmod ug+rx Tools/config/install-sh
make install
 
#should be installed in ~/swig now; e.g. ~/swig/bin/swig should work
~/swig/bin/swig -delphi -version

Download

Linux x86 binaries compiled via the procedure above:

Linux x64 binaries compiled via the procedure above:

Development

It would of course be very welcome if somebody

  • got the current version into main SWIG so it is more easily usable
  • improve the code

Additionnally, binary releases for e.g. Linux and Windows are warmly welcome for upload to e.g. the BitBucket repository. Please contact forum user BigChimp for that.

See also