Binary python extensions with Free Pascal Compiler

Skip to first unread message

Caleb Hattingh

Mar 16, 2006, 3:49:03 PM3/16/06
Hi all

I want to write python extensions with FPC (Free Pascal Compiler, In Delphi, this is trivially easy due to
the great work of the P4D (Python-for-Delphi,
guys; however, when aiming for cross-platform binary extensions, that
strategy naturally doesn't work.

FPC has great cross-platform support, and to date I have written
library units that compile to .dlls (on win32) and .so's (on posix),
and then used these via ctypes. This has worked very well, but for
certain applications I would prefer to create a new python type via
binary extension, rather than a python class with method wrappers
around library calls. I could just use C, I guess, but I have a large
amount of pascal code that I would like to use, and I would prefer not
to fiddle with a C-binary extension intermediate.

I have explored the python.h header, and as expected, there appears to
be much use of the C standard library. Using a tool that converts a C
header into an object pascal unit (intended to be the interface to
python.dll) gets me some of the way, but of course, calls to the C
stdlib don't get automatically translated into equivalent pascal-coded
functionality. I'm afraid I am answering my own question here: is the
only way of getting this working to change all the stdlib calls in my
newly created pascal unit (created from python.h) to matching
functionality in pascal?

If there is another, simpler way I'm just not seeing, I would be glad
to hear it.


Ravi Teja

Mar 16, 2006, 3:59:50 PM3/16/06
I posted this a few days ago. According to the website
(, FPC support
has been added since version 3.29.

Caleb Hattingh

Mar 16, 2006, 4:03:19 PM3/16/06
Well, there it is:

* Added support for Free Pascal Compiler (
and Lazarus Project (
Thanks to Michiel du Toit (

That was easy. I just saw the new support for D2k6 recently.

thx Ravi

Reply all
Reply to author
0 new messages