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

C++BuilderDelphiFiremonkeyIDELibraryUtilityWindows

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

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSSWIG 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:

/* File : gif_lib.i */
%module gif_lib

%{
#include "gif_lib.h"
#include "gif_hash.h"
#include "gif_lib_private.h"
%}

/* Let's just grab the original header file here */
%include "gif_lib.h"
%include "gif_hash.h"
%include "gif_lib_private.h"

And a sample command line would be:

swig -delphi -c++ gif_lib.i

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
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

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

Sign up for our Newsletter and
stay informed

Leave a Reply