probs w/ building python extensions on free Microsoft.NET SDK

Shakeeb Alireza sa at bayt.net
Tue Aug 7 03:09:00 EDT 2001


meekly...

It seems newbieness (like everthing) is a function of time. If I spent more
time (w/ the documentation, it seems...:-) I would have reached the
exquisite point of "python setup.py build" sooner. Thank you distutils. Now
I will import noddy until i fall asleep....

I concur with those who have said that the extension and embedding docs are
simply not meant for newbies. However, one should accept the possibility
(given that python is positioned as a CP4E language) that beginners (who
might actually be somewhat proficient at python) will attempt to sample C
(and other langs) in the quest to deal with 'perceived' issues such as
performance, etc... I certainly don't think it's a problem if I want python
to be my window into other languages.

So in my particular case... I wouldn't mind if this trajectory via simpler
documentation was made somewhat smoother: less rapid context switching
between unix and windows and a "hello world w/ python setup.py
build" example on a single page would be nice. Maybe it's just me but I
found the
current docs on the topic slightly dense until something slapped me on some
page about a NoddyType and told me it's actually much easier than it seems
because its python.

ok...I think I might just attempt something like this for my particular
case. Here goes:

"Compiling CPython Extensions using MicroShaft's .NET SDK" - for naughty
newbies who like freebies and don't like baby steps.
    [platform: win2k, python 2.1.1, Microsoft .Net SDK]


1. download and install the M$ .Net SDK from
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?ur
l=/msdn-files/027/000/976/msdncompositedoc.xml&frame=true

2. from the python 2.1.1 src distribution grab example.c
(path:Python-2.1.1\PC\example_nt\example.c)
and place it in any directory x

3. create file called 'setup.py' with code below and save it (along with
example.c) in directory x:

 from distutils.core import setup, Extension
 setup(name = "example", version = "1.0",
      ext_modules = [Extension("example", ["example.c"])])

4. cd to folder x and type the following :

 python setup.py build

5. barring any fatal errors, a new "build" directory has appeared in x, cd
to its "lib.win32-2.1" subdirectory. You should find an example.pyd file in
it.
Kick into python interactive mode and test the extension:

ActivePython 2.1.1, build 212 (ActiveState)
Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import example
>>> example.foo()
Hello, world
>>>

6. NOW read the real documentation:
http://python.sourceforge.net/devel-docs/ext/ext.html
but _BEFORE_ that please learn how to speak in C. Kernighan & Ritchie's
"Programming in C" is supposed to be *the* starter...
[http://cm.bell-labs.com/cm/cs/cbook/]


PS:I guess the nice conclusion of this minor adventure is that you don't
have to shell out hard-earned cash on visual something or the other to
compile python extensions on MicroShaft's c/c++ compiler... just download
their .NET SDK. (much better to spend it on python software/books of course)

Of course there's always the cygwin thing...

ok let's try it on the same files (setup.py as above and example.c):

sa at local ~
$ python setup.py build
running build
running build_ext
building 'example' extension
skipping example.c (build/temp.cygwin_nt-5.0-1.3.2-i686-2.1/example.o
up-to-date
)
gcc -shared -Wl,--enable-auto-image-base
build/temp.cygwin_nt-5.0-1.3.2-i686-2.1
/example.o -L/usr/lib/python2.1/config -lpython2.1 -o
build/lib.cygwin_nt-5.0-1.
3.2-i686-2.1/example.dll
Cannot export _bss_end__: symbol not defined
Cannot export _bss_start__: symbol not defined
Cannot export _data_end__: symbol not defined
Cannot export _data_start__: symbol not defined
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

o well...

still a newbie-ly-yrs..

Shakeeb





More information about the Python-list mailing list