Create Wrapper Interfaces For C and C++ Libraries Using SWIG With Delphi Support

SWIG is a tool which will automatically (mostly) create an interface for a C and C++ project for a variety of other programming languages. It does this by translating the C/C++ headers into the target language and sometimes by creating a wrapper library around the original library to make interfacing easier. Historically Delphi was not one of the languages supported in SWIG. There was an effort made a few years ago which got a working version of SWIG 2.0 for Delphi but the latest version of SWIG is 3.0. That older version is available over on BitBucket. I had a developer over on UpWork put quite a bit of time into adding support for Delphi into SWIG 3.0 and that code is now available on Github. The Delphi support in not 100% as of yet but it is workable and greatly simplifies the process of making C and C++ libraries available to your Delphi code. At the moment you may have to do some fix it work on the generated code after running SWIG on the header files. Feel free to submit fixes back to the GitHub repo and/or report any problems with creating interfaces you may find so everyone can benefit from an improved tool. SWIG is pretty complex so it is not for the faint of heart but if you need access to serious C and C++ libraries from Delphi it is a good place to start. You can find out more information about SWIG over on their website. You will need to create a SWIG interface file like the below in order to process a C or C++ header file with SWIG. You can also customize the interface file for any manual translation of objects or code that needs to take place for the specific library you are running SWIG against.

Example libGIF interface file for SWIG:

And a sample command line would be:

Download the full source code plus Windows binaries (and required DLLs) of SWIG with support for Delphi.

Head over to GitHub and download the full source code for the SWIG with Delph support project or to file bugs you find.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Create Wrapper Interfaces For C and C++ Libraries Using SWIG With Delphi Support by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Build A Cross Platform REST Client With FireMonkey In Delphi 10 Berlin On Android, IOS, OSX, And Windows

Delphi with the FireMonkey framework is a great tool to quickly build REST clients. I wanted to build out a...

Close