[C++-sig] incorrect linking to libpython (Dane Springmeyer)

Amos Anderson nitroamos at gmail.com
Mon Mar 1 21:08:22 CET 2010

> Message: 2
> Date: Fri, 26 Feb 2010 18:36:16 -0800
> From: Dane Springmeyer <blake at hailmail.net>
> To: Development of Python/C++ integration <cplusplus-sig at python.org>
> Subject: Re: [C++-sig] incorrect linking to libpython
> Message-ID: <57569986-7D90-4686-8384-809F8D27FC68 at hailmail.net>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
> Amos,
> I feel your pain, seriously. I've been down many of these paths as well.
> My overall sense is that direct linking of boost to a python
> executable may not be necessary, and rather that bjam could use `-
> undefined dynamic_lookup`, which will mean that when you import the
> python module you've built with boost::python the right version of
> python will be dynamically looked up based on the interpreter you are
> running. There are certainly potential problems with this route (and
> I've only lightly tested so far) but I think it may hold promise.
> More to the point, I've also got into the habit of passing -Z to the
> linker to make sure that if the custom python framework is not able to
> be linked, ld does not fallback to linking to the "system" or apple
> provided python framework and rather throws an error so you know the
> exact point things went wrong rather than only later by getting the
> dreaded "Version Mismatch" error.
> Failing to link to the /Library or user installed python26 is almost
> invariably the case on snow leopard because two copies will exist and
> the user installed version won't be preferentially linked with the
> normal -L/path/to/dir -lpython2.6 method because 'libpython2.6' is
> actually:
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/
> libpython2.6.a
> and my sense is the linker will prefer the /usr/lib/libpython2.6.dylib
> over that because of the 'a' (even though it is actually, and oddly, a
> symlink to the dynamic library at:
> /Library/Frameworks/Python.framework/Versions/2.6/Python
> So, one workaround is symlinking:
> /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/
> libpython2.6.dylib  -> ../../../Python
> Then bjam should be able to find it.
> But I think a preferable method would be if bjam actually sent the
> linker line:
> -F/Library/Library/Frameworks -framework Python -Z
> instead of -L/etc/etc -lpython...
> Dane
> More info on those ld commands at:
> http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/ld.1.html

I can confirm that your solution fixed the problem. Actually, I just did this:

sudo cp libpython2.6.a libpython2.6.dylib

(and recompiled boost python)



More information about the Cplusplus-sig mailing list