[fpc-pascal] Python

Krishna v.krishnakumar at gmail.com
Mon Feb 16 04:12:35 CET 2009

On Mon, Feb 16, 2009 at 6:25 AM, Xealot <xealot at gmail.com> wrote:
> Hello everyone,
> I appologize if this is not the correct mailing list for this kind of
> question.
> I want to use Python from my application, i found a couple of ways to do
> this. either use P4D in Windows (which would not compile on my 64 bit
> system, and is not cross platform), I can translate the necessary functions
> and classes from the python header files myself (h2pas wont work) and work
> directly against the library..
> Or the third option, which I tried on linux.. which is to write the code
> that actually uses python in C, compile it with gcc and then link the
> resulting .o file into the rest of my application and use that. With this
> method, I can use all of pythons API without having to translate its
> headers, This trick worked in Linux when I tested it, but im having issues
> in Windows
> Whilst the compile of the actual C code worked, I simply cannot use the
> Python25.dll from my code,  Heres how I did it:
> unit pyinterface;
> {$link py.o}
> {$linklib python25}
> {$linklib c}
> On windows, I used the MingW compiler so linklib c was to be replaced with
> the appropriate libraries (msvcrt etc.) but this is not the issue,
> the problem here is that when I try to linklib python25, It produces:
> C:\test\C>C:\FPC\2.2.2\bin\i386-win32\ppcrossx64.exe
> -FlE:\mingw-w64-bin_i686-mi
> ngw_20090213\x86_64-pc-mingw32\lib64 -FlC:\test\C -FoE:\Python25\libs
> foo.pas
> foo.pas(19,1) Error: Import library not found for python25
> doesnt matter if i put python25 or python25.dll in the linklib line, and the
> DLL is present both in my System32 directory, as well as in the local one
> where all the source code for my demo project is in.

a linklib under mingw will generate an option like -lpython25 which
makes ld.exe search for libpython25.a in the standard library paths.
you have two options: you can generate an import library libpython25.a
from python25.dll using dlltool. I forgot the exact switches so google
for it.

The second option is autolinking: you link directly with the DLL.
Mingw supports it but the name of the dll needs to be passed to it
directly without the -l switch. Not sure whether that can be done with


I love deadlines. I like the whooshing sound
they make as they fly by.
    -- Douglas Adams

More information about the fpc-pascal mailing list