[Pythonmac-SIG] Using distutils with XCode
Paul Kinnane
pkinnane at internode.on.net
Tue Oct 4 06:13:43 CEST 2005
Chris
Thanks so much for your help on this.
> By the way, I always do the build and install steps separately:
That works well - although I get the same error. But that is a good way
to do the "install". Thanks
> Which gcc are you using?
4.0 - which is the version that python was compiled with.
> I doubt it. It is in libstdc++
Well I couldn't find any trace of a file called "libstdc*" on my Mac, so
maybe it isn't installed?
I have recompiled ode, ensuring it was done with gcc4. Python is
compiled with gcc4. Re-ran the "python setup.py build", which continued
to give the __cxa_pure_virtual error.
So I replaced the gcc link command with g++, and now when I do "import
ode" in python I get...
ImportError: Loaded module does not contain symbol _initode2
Which seems to indicate a problem with the ODE build.
I've recompiled both ODE and the python wrapper with gcc 3.3 AND g++
(3.3), and in both cases the same error is given as above.
The link command that is being issued by setup.py is...
g++ -L/sw/lib -bundle -flat_namespace -undefined suppress
build/temp.darwin-8.0.0-PowerMacintosh-2.2/ode.o -L../ode-0.5/lib -lode
-o build/lib.darwin-8.0.0-PowerMacintosh-2.2/ode.so
There are no link errors.
Paul
-----Original Message-----
From: Chris Barker [mailto:Chris.Barker at noaa.gov]
Sent: Tuesday, 4 October 2005 2:10 AM
To: Paul Kinnane; pythonmac-sig at python.org
Subject: Re: [Pythonmac-SIG] Using distutils with XCode
Paul Kinnane wrote:
> OK, I found I could compile and successfully import the test.c sample
> from http://www.nevada.edu/~cwebster/Python/MPWHOWTO/MPWHOWTO.html
using
> the Darwin "python setup.py install" command.
>
> However, I'm trying to compile a wrapper for the ode physics engine.
> The wrapper is call PyODE (http://pyode.sourceforge.net/) and I've
> successfully compiled it on the Windows platform and been able to
import
> it into python.
>
> Using "python setup.py install", I get a permissions error. I assume
> there is a simply way for me to get the right access rights in Darwin
to
> do an install?
sudo python setup.py install.
"sudo" is Super User Do. It will prompt you for a password, ans if you
are an administrative user, you will get full administrative privileges
for the command that follows. this is the standard OS-X way to do
anything administrative from the command line.
By the way, I always do the build and install steps separately:
python setup.py build
sudo python setup.py install
It's best to do as little as possible as the super user.
>Anyway, doing a build and then manual install gives the
What's a "manual install", and how did you build? What exactly did you
do? Which gcc are you using?
> following error when trying to import into Python...
>
> ImportError:Failure linking new module: ode.so: Symbol not found:
> ___cxa_pure_virtual
> Reference from:ode.so
> Expected in:Flat namespace
> Researching the web there was a
> lot of info about using g++ instead of gcc for linking etc, which
coming
> from the Win platform was a little confusing.
I'm pretty sure that a properly written setup.py and distutils should
take care of that for you, but I haven't written any setup.py scripts
for C++ myself, so I don't know how. A couple years ago, however, I did
have this kind of problem with a C++ file. In that case, it didn't
actually use an C++ features, so I changed the syntax a little to make
it C, and solved it that way, which isn't going to help you any. In that
case the same file worked just fine on Linux, but he way, so OS-X is
pickier for some reason. Here is the solution I was offered, that I
never tried:
"""
This just came by on another mailing list. The problem is that the link
step is done with "gcc", not "g++", so you have to add the C++ library
by hand. The easiest is to add an extra_link_libraries (iirc) flag to
the setup.py file.
"""
> 1) Is there any difference between compiling the extern library
wrapper
> in gcc verses XCode?
No. Xcode is a front-end to gcc. However, it might be hard to make sure
all the same flags are used.
> 2) If I can use gcc, should I only use gcc3.2? (as recommended in
some
> msg threads)
I'm still running OS-X 10.3, which uses gcc3.3, so I'm not sure.
However, while it may not be strictly necessary, it's probably safer to
use the same gcc as python was compiled with. When you start up python,
the startup message should tell you.
> 3) Is defining ___cxa_pure_virtual in the link statement the correct
way
> to resolve that problem?
I doubt it. It is in libstdc++. I've seen a message on the matplotlib
that it isn't in all versions, however. I do find it in the version on
my machine (6.0.3). Perhaps if you use the same gcc as python was
compiled with, you'll be OK.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Pythonmac-SIG
mailing list