[Pyrex] Newbie question
Phillip J. Eby
pje at telecommunity.com
Thu Aug 5 14:29:42 CEST 2004
At 11:37 AM 8/5/04 +0200, JC wrote:
>Fisrt excuse me for my poor english...my mother tongue is french...
>
>It could seems to be an 'idiot' question but my problem is quite simple:
>How to write one single extension (let's say 'mycommoncasses.pyd) from
>several .pyx sources containing python classes ?
You can't; either use .pxi files and include them, or make two separate
modules.
>setup(
> name = "myClasses",
> ext_modules=[
> Extension("mycommoncasses", ["someclasses.pyx","otherclasses.pyx"])
> ],
> cmdclass = {'build_ext': build_ext}
>)
>
>but it fails like this:
>d:\cygwin\bin\gcc.exe -mno-cygwin -mdll -static -s
>build\temp.win32-2.2\Release\
>someclasses.o build\temp.win32-2.2\Release\otherclasses.o
>build\temp.win32-2.2\Release\mycommoncasses.def -Lc:\Python22\libs
>-lpython22 -o mycommoncasses.pyd
>Cannot export initmycommoncasses: symbol not defined
>collect2: ld returned 1 exit status
>error: command 'gcc' failed with exit status 1
This is because Python wants to call a function 'initmodulename' where
'modulename' is the module name. Pyrex generates a .c for each .pyx, that
contains an 'initpyxfilename' method. So, unless at least one of your .pyx
files is named "mycommoncasses", you'll get this error. But, the other
.pyx files won't be usable if you do that, because *their* initialization
functions won't get called by Python. As a result, their classes and
functions will not show up in the module dictionary, and if you use them in
Pyrex you will probably crash the interpreter as e.g. string constants
won't be initialized.
More information about the Pyrex
mailing list