Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!


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.

There was also some additional work done to the Delphi support for SWIG in this repo.


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

Related posts

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores


DelphiCon 2020 FireMonkey Sessions Available Starting November 19


Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply