Extensions with LCC

Robert Kern kern at caltech.edu
Mon Oct 30 03:01:08 EST 2000


In article <39FD7EDC.EF818DA2 at helsinki.fi>, "Kimmo
=?iso-8859-1?Q?P=E4=E4kk=F6nen?=" <Kimmo.Paakkonen at helsinki.fi> wrote:

>   Hi, I'm new to Python, so these questions may be trivial or some
>   basics
> may be not well understood (at least I feel puzzled enough :).
>   I'm trying to compile an extension to the Python. I'm working on
> Windows NT and as a compiler I use (freely available) LCC compiler,
> 
> http://www.cs.virginia.edu/~lcc-win32/index.html

I tried this once and gave up on it for mingw32. IIRC, LCC may come
with its own runtime library which will conflict with the MSVC runtime 
library in bizarre ways.

> After making tensormodule.c file by using python api, I tried to compile
> it but got these error messages: Error tensormodule.c 89 undefined
> reference to __imp__Py_InitModule4 Error tensormodule.c 78 undefined
> reference to __imp__Py_BuildValue Error tensormodule.c 41 undefined
> reference to __imp__PyFloat_AsDouble etc.. It gives me error messages
> for all the python C api commands. It does find the python.h file, but I
> guess I would need to tell it which library to link it with? I tried
> giving include paths to python/include directories etc without success,
> and tried even bring some source files from python sources to my
> project, but got just more, different errors.

This is a link error, not a compile error. You need to make an import 
library from the python20.dll and link against that library. See the LCC 
documentation on how to do that.

> I also tried out using GCC/mingw32 compiler, as I found instructions of
> how to use it to make extensions, but I got error message of
> 
> ImportError: Module use of python15.dll conflicts with this version of
> Python
> 
> when I tried to run my python program.

Right. You linked against python15.dll and ran the module with Python 2.0.

> With the instructions there was
> modified header files for the python, so I doubt they would work with
> version 2.0 (but I haven't tried it yet).

The 2.0 headers would have to be patched similarly. The only differences
between the canonical set and the mingw32 set are that config.h has the
mingw32 information, mostly adapted from the MSVC information, and the
macros DL_CLASS_IMPORT_BEG and DL_CLASS_IMPORT_END around some of the
structure definitions.

You can try taking the distributed win32 config.h, add the stuff from the
(1.5.2) mingw32 config.h, and add the DL_CLASS_IMPORT_* macros around
the same structures, and maybe a few others if you run into problems.

In fact, I think that the link errors you got were the motivation for
these modifications. So you may have to do the same thing to use LCC.

> Unfortunately I don't have Visual Studio, so I can't use the "cookbook
> approach". Is there any detailed instructions somewhere how you do
> things with other compilers?

Someone recently announced instructions and import library for using
Borland's free compiler to compile extensions for 1.5.2 and 2.0.  I don't
have the URL on me, though.

> For example, I'm still confused if I do
> need source code or not, as the GCC/Mingw32 instructions worked without
> them (but it had libpython15.a file with it, and the modified header
> files).

I think the canonical win32 distribution comes with the includes and the
MSVC import library. That plus some elbow grease should be all you need 
to get started working on this.

> I would prefer LCC as it is the compiler I'm most familiar with.
> Any help appreciated!
> 
>                 Kimmo Pääkkönen Kimmo.Paakkonen at helsinki.fi

-- 
Robert Kern
kern at caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."



More information about the Python-list mailing list