Can't load .pyd files from embedded Python interp

edream at tds.net.bbs edream at tds.net.bbs
Mon Jul 17 19:00:02 EDT 2000


Hey!  Clean link, proper execution! Yippee.

> >I'll write up my experiences when I've successfully embedded Python in
> >my app.  For now the conclusion seems to be that one only need link in
> >C:\Windows\System\python15.dll to the app.  There are some details
> >specific to Borland, but presumably they won't be difficult.

Getting a clean link was straightforward. I renamed
c:\Windows\System\python15.lib to be python(orig)15.lib, then ran the
Borland IMPLIB utility that creates import libs as follows:

IMPLIB -a python15.lib python15.dll

The -a option adds '_' alias for cdecl functions for compatibility with
Microsoft libraries.  After running IMPLIB one should _not_ declare
functions with the __declspec attribute; just #include "python.h" and
the linker is happy.  Don't ask me why, maybe it's the -a options, maybe
it's IMPLIB itself, maybe its magic.

To link, I just added python15.dll and python15.lib to the project.
That's all.

I've just stepped through the following statements in my test app with
no apparent problems:

    Py_Initialize();
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("for i in sys.path: print i");
    PyRun_SimpleString("import parser");

Well, err, stderr and stdout seem to have disappeared, but that's
another issue.  Presumably there is a way to send output to a window, a
la Pythonwin.  Heh, heh.

Warning Redux:  you must not call any of the misnamed "very high level"
functions in the C API that have FILE * arguments when using the Borland
compiler because Borland's idea of a struct FILE is not the same as
Microsoft's.  It's really too bad that there are _no_ "very high level"
functions in the C API that will open a file for you.  This should be
fixed, and it would be trivial to do so.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edream at tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------



More information about the Python-list mailing list