[Pythonmac-SIG] C module creation on MacPython

Corran Webster cwebster@nevada.edu
Fri, 22 Oct 1999 15:02:02 -0700 (PDT)


> Hello:
> 
> Can I get some pointers on how C modules are created for MacPython?
> 
> Specifically, I'm looking to use the sgmlop module from the madscientist
> (www.pythonware.com/madscientist) and its only available as c source.
> 
> What is needed to create a c module in MacPython?

Doug Wyatt gave some pointers for compiling with CodeWarrior.  If you
don't have CodeWarrior, you can download MPW from Apple's ftp site for
free and compile using that.

You'll need to extract the Include files from the standard mac
distribution (do a custom install from the Installer) or from the source
distribution.

You can then compile and link from the MPW command line, or for more
complex projects, set up a Makefile to build for you.  Typical compilation
commands for a single-file module might look like:

set Python "your path to python folder"

MrC "mymodule.c" -o mymodule.c.x -w off -i "{Python}Mac:Include:" -i
"{Python}Include:"

PPCLink -o mymodule.ppc.slb "mymodule.c.x"  -t 'shlb' -c 'Pyth' -xm s
"{SharedLibraries}InterfaceLib" "{SharedLibraries}MathLib"
"{SharedLibraries}StdCLib" "{PPCLibraries}StdCRuntime.o"
"{PPCLibraries}PPCCRuntime.o" "{PPCLibraries}PPCToolLibs.o"
"{Python}PythonCore" -export initMyModule

(you can break lines with the partial derivative symbol option-d)

You may need to include other libraries, or not include some of the ones
I've included, depedning on what your module does.  I think there should
be an option to turn off certain warnings in the second command, too, but
I'm too lazy to look it up.

Anyway, presuming correct compilation, you will then have a compiled
module that you can place somewhere that Mac Python will find it, and then
you can import it like any other module.

I'm sort of a newbie at this, so I hope I haven't left anything out - I
just hacked around until I got things to work with MPW.

Regards,
Corran