logo       

Re: Newbie Question (problems with GCC): msg#00026

python.pyrex

Subject: Re: Newbie Question (problems with GCC)

In actual the reply from Greg might contain the answer to my further difficulties :-)

However - below are the resutls of my *failed* experiments last night.............

I thought I'd followed the instructions in :
http://randomthoughts.vandorp.ca/syncato/WK/blog/758_Simple_instructions_to_compile_python_C_extensions_in_windows.item
to the letter !
(Thanks for the replies by the way - both Phillip and Greg).

Now the 'random thoughts' page says that after installing MinGW successfully and adding a disutils.cfg file (which didn't exist already).... I ought to be able to compile extensions from disutils automagically.................

However it seems that maybe :

python setup.py build_ext --compiler=mingw32

is the right way instead.... (I'll try it when I get home)

I print the resutls I got below as they seem suspiciously wrong anyway..........
(When attempting to compile primes.pyx )

The setup.py I used was :
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
setup(
name = "PyrexGuide",
ext_modules=[ Extension("mymodule", ["primes.pyx"])
],
cmdclass = {'build_ext': build_ext}
)

At first I just tried setup.py build --inplace (as per one of the tutorials)
but this was invalid options... so I tried just "setup build" with the
following results.

After that (as you will see) I tried the method in the tutorial suggested for Linux, calling gcc directly - with suitably obscure results....... (I seemed to get a 'primes.o' file - but no further).

###########
ATTEMPT 1

F:\Python Projects\c>setup.py build
running build
running build_ext
error: Python was built with version 6 of Visual Studio, and extensions need to
be built with the same version of the compiler, but it isn't installed.

F:\Python Projects\c>



#####################

ATTEMPT 2

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

F:\Python Projects\c>pyrexc.py primes.pyx

F:\Python Projects\c>gcc -c -fPIC -IC:\Python23\include primes.c
cc1.exe: warning: -fPIC ignored for target (all code is position independent)

F:\Python Projects\c>gcc -shared primes.o -o primes.so
primes.o(.text+0x5f):primes.c: undefined reference to `_imp__PyArg_ParseTupleAnd
Keywords'
primes.o(.text+0x7c):primes.c: undefined reference to `_imp___Py_NoneStruct'
primes.o(.text+0x94):primes.c: undefined reference to `_imp__PyList_New'
primes.o(.text+0x1f5):primes.c: undefined reference to `_imp__PyObject_GetAttrSt
ring'
primes.o(.text+0x22f):primes.c: undefined reference to `_imp__PyInt_FromLong'
primes.o(.text+0x268):primes.c: undefined reference to `_imp__PyTuple_New'
primes.o(.text+0x2c4):primes.c: undefined reference to `_imp__PyObject_CallObjec
t'
primes.o(.text+0x4e3):primes.c: undefined reference to `_imp__Py_InitModule4'
primes.o(.text+0x4fa):primes.c: undefined reference to `_imp__PyImport_AddModule
'
primes.o(.text+0x51d):primes.c: undefined reference to `_imp__PyObject_SetAttrSt
ring'
primes.o(.text+0x5a2):primes.c: undefined reference to `_imp__PyString_FromStrin
g'
primes.o(.text+0x5c0):primes.c: undefined reference to `_imp__PyString_FromStrin
g'
primes.o(.text+0x5e1):primes.c: undefined reference to `_imp__PyModule_GetDict'
primes.o(.text+0x5fe):primes.c: undefined reference to `_imp__PyTuple_New'
primes.o(.text+0x61e):primes.c: undefined reference to `_imp__PyString_FromStrin
g'
primes.o(.text+0x662):primes.c: undefined reference to `_imp__PyCode_New'
primes.o(.text+0x682):primes.c: undefined reference to `_imp__PyThreadState_Get'

primes.o(.text+0x68d):primes.c: undefined reference to `_imp__PyFrame_New'
primes.o(.text+0x6b4):primes.c: undefined reference to `_imp__PyTraceBack_Here'

F:\Python Projects\c>

Regrads,


Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



Greg Ewing wrote:

Michael <mike@xxxxxxxxxxxx>:


What's worse - I will need to learn the magic compiler chain
incantations that I have avoided for so long.


You can avoid most of that by using distutils to build your
extension. Pyrex comes with a distutils extension that knows about
.pyx files.


I've got the MinGW package with gcc - which is probably the *best*
free compiler - although I understand there are issues with easily
using it for pyrex/win32.


Distutils can use MinGW. You just need to say

python setup.py build_ext --compiler=mingw32

The only tricky part is that you need to use a couple of command-line
tools to create a MinGW version of the Python DLL for linking the
extension against. There are instructions for doing this in the Python
distutils documentation. You only need to do it once for any given
Python version.


Has anyone any experience of doing this ?


Yes, I've done it myself recently, and it works fine.


Can compiled extensions be distributed for use by people without MinGW
*and* without dependency on an extra dll as a result of using this
method ?


Yes.


Will my resulting binary be free of GPL restrictions ?


Yes.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg@xxxxxxxxxxxxxxxxxxxxx +--------------------------------------+

_______________________________________________
Pyrex mailing list
Pyrex@xxxxxxxxxxxxxxxxx
http://lists.copyleft.no/mailman/listinfo/pyrex





--

http://www.Voidspace.org.uk The Place where headspace meets cyberspace. Online resource site - covering science, technology, computing, cyberpunk, psychology, spirituality, fiction and more.
---
http://www.atlantibots.org.uk
http://groups.yahoo.com/group/atlantis_talk/
Atlantibots - stomping across the worlds of Atlantis.
Building with Python - programming language that rules the world.
---
http://www.fuchsiashockz.co.uk http://groups.yahoo.com/group/void-shockz
---

Everyone has talent. What is rare is the courage to follow talent
to the dark place where it leads. -Erica Jong
Ambition is a poor excuse for not having sense enough to be lazy.
-Milan Kundera


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise