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



On Feb 26, 2010, at 3:47 PM, Amos Anderson wrote:

Hello --

summary: I'm trying to compile the boost python library using a custom
installed python on osx. however, it appears to be linking to the
system library, not the installed library.


I'm using OSX 10.6.2, which has python 2.6.1 by default. I wanted to
try to install 2.6.4 just to see how the process works. I
To install python, I did this:
./configure  --enable-framework
make
make install

which put the distribution here:
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6

I changed a boost config file to read:
using python
     : 2.6
     : /Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
: /Library/Frameworks/Python.framework/Versions/2.6/include/ python2.6 : /Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/config ;

and compiled the library. However, when I examine the library itself:
% otool -L libboost_python.dylib
libboost_python.dylib:
libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0)
        /System/Library/Frameworks/Python.framework/Versions/2.6/Python
(compatibility version 2.6.0, current version 2.6.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 125.0.0)

I can see that it linked to the system's version. Why did it choose
that one? The problem is that when I run my code, I get the error:
Fatal Python error: Interpreter not initialized (version mismatch?)
../../../triad.sh: line 9: 59136 Abort trap              python $@


the OS gives me a popup window mentioning all the linked libraries:
Binary Images:
      0x100000000 -        0x100000ff7 +org.python.python 2.6.4
(2.6.4) <536A2002-9AEC-D7DF-8C2B-6C634FB7F37E>
/Library/Frameworks/Python.framework/Versions/2.6/Resources/ Python.app/Contents/MacOS/Python
      0x100003000 -        0x100153fe7 +org.python.python 2.6.4, (c)
2004-2008 Python Software Foundation. (2.6.4)
<3B4D8CE1-8D9C-97CB-57BA-A8F4C40CE5F0>
/Library/Frameworks/Python.framework/Versions/2.6/Python
      0x1002e7000 -        0x1002e8ff7 +time.so ??? (???)
<CB23D26C-1417-4D31-9E06-1E33CCDCA83C>
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib- dynload/time.so
      0x100480000 -        0x100493fef +libgcc_s.1.dylib ??? (???)
<E51F2952-8BEB-C427-10A9-672FC10E3A54> /usr/local/lib/libgcc_s.1.dylib
      0x100753000 -        0x10077bfff +libboost_wserialization.dylib
??? (???) <4FD94C16-75D0-DE5D-A27B-E3AEAEEA8CCC>
/Users/amos/triad/trunk/lib/libboost_wserialization.dylib
      0x101000000 -        0x1013eeff7 +triad.so ??? (???)
<EEF65664-60F0-E721-06A8-82F88CEA1EFC>
/Users/amos/triad/trunk/lib/triad.so
      0x1020eb000 -        0x102124fef +libboost_serialization.dylib
??? (???) <33DB6DD1-4712-AEE1-0761-18054566A5E4>
/Users/amos/triad/trunk/lib/libboost_serialization.dylib
      0x1021b1000 -        0x1021f0ff7 +libboost_python.dylib ???
(???) <67258016-C11E-8EDF-BF36-103DBC219C78>
/Users/amos/triad/trunk/lib/libboost_python.dylib
      0x10223e000 -        0x10234eff7  org.python.python 2.6.1
(2.6.1) <01EBD0D4-F181-045F-C7A8-B7B3C5D4204F>
/System/Library/Frameworks/Python.framework/Versions/2.6/Python
   0x7fff5fc00000 -     0x7fff5fc3bdef  dyld 132.1 (???)
<B633F790-4DDB-53CD-7ACF-2A3682BCEA9F> /usr/lib/dyld
   0x7fff813dc000 -     0x7fff81459fef  libstdc++.6.dylib ??? (???)
<35ECA411-2C08-FD7D-11B1-1B7A04921A5C> /usr/lib/libstdc++.6.dylib
   0x7fff81f2c000 -     0x7fff81f3dfef  libz.1.dylib ??? (???)
<3A7A4C48-A4C8-A78A-8B87-C0DDF6601AC8> /usr/lib/libz.1.dylib
   0x7fff846e0000 -     0x7fff846e4ff7  libmathCommon.A.dylib ???
(???) <95718673-FEEE-B6ED-B127-BCDBDB60D4E5>
/usr/lib/system/libmathCommon.A.dylib
   0x7fff888bb000 -     0x7fff88a79ff7  libSystem.B.dylib ??? (???)
<526DD3E5-2A8B-4512-ED97-01B832369959> /usr/lib/libSystem.B.dylib
   0x7fffffe00000 -     0x7fffffe01fff  libSystem.B.dylib ??? (???)
<526DD3E5-2A8B-4512-ED97-01B832369959> /usr/lib/libSystem.B.dylib

Where i've deleted all the lines with my libraries. Note: I can do this:
/Library/Frameworks> sudo mv Python.Framework temp.Python.Framework
and then everything works fine. So I assume that the problem is the
one python file 2.6.1 which didn't come from the same python path as
the other python paths. When I compile, I get this:
% bjam -d 2 release
...
deleted similar lines
....
   "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline
-Wall -dynamic -no-cpp-precomp -gdwarf-2 -fPIC  -DBOOST_ALL_NO_LIB=1
-DBOOST_PYTHON_SOURCE -DNDEBUG
-I"/Library/Frameworks/Python.framework/Versions/2.6/include/ python2.6"
-I"boost/boost_1_40_0" -c -o
"boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ import.o"
"boost/boost_1_40_0/libs/python/src/import.cpp"

darwin.compile.c++
boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ exec.o

   "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline
-Wall -dynamic -no-cpp-precomp -gdwarf-2 -fPIC  -DBOOST_ALL_NO_LIB=1
-DBOOST_PYTHON_SOURCE -DNDEBUG
-I"/Library/Frameworks/Python.framework/Versions/2.6/include/ python2.6"
-I"boost/boost_1_40_0" -c -o
"boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ exec.o"
"boost/boost_1_40_0/libs/python/src/exec.cpp"

darwin.compile.c++
boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/function_doc_signature.o

   "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline
-Wall -dynamic -no-cpp-precomp -gdwarf-2 -fPIC  -DBOOST_ALL_NO_LIB=1
-DBOOST_PYTHON_SOURCE -DNDEBUG
-I"/Library/Frameworks/Python.framework/Versions/2.6/include/ python2.6"
-I"boost/boost_1_40_0" -c -o
"boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/function_doc_signature.o"
"boost/boost_1_40_0/libs/python/src/object/function_doc_signature.cpp"

darwin.link.dll
boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ libboost_python.dylib

   "g++" -dynamiclib -Wl,-single_module -install_name
"libboost_python.dylib"
-L"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ config" -o "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ libboost_python.dylib" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ numeric.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ list.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ long.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ dict.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ tuple.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ str.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ slice.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ converter/from_python.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ converter/registry.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ converter/type_id.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/enum.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/class.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/function.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/inheritance.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/life_support.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/pickle_support.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ errors.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ module.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ converter/builtin_converters.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ converter/arg_to_python_base.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/iterator.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/stl_iterator.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object_protocol.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object_operators.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ wrapper.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ import.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ exec.o" "boost/boost_1_40_0/bin.v2/libs/python/build/darwin-4.2.1/release/ object/function_doc_signature.o"
-lpython2.6    -headerpad_max_install_names -Wl,-dead_strip
-no_dead_strip_inits_and_terms

So again we can see that it's finding the header files for each object
file, but then when they're all being linked, it's seems to be
skipping the library that (I think) it should be picking:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ config> ls -lrt
total 208
-rw-r--r--  1 root  admin   3.7K Feb 26 12:25 python.o
-rwxr-xr-x@ 1 root  admin   7.3K Feb 26 12:25 makesetup*
-rwxr-xr-x@ 1 root  admin   7.0K Feb 26 12:25 install-sh*
-rw-r--r--@ 1 root  admin   1.4K Feb 26 12:25 config.c.in
-rw-r--r--  1 root  admin   2.0K Feb 26 12:25 config.c
-rw-r--r--  1 root  admin    41B Feb 26 12:25 Setup.local
-rw-r--r--  1 root  admin   368B Feb 26 12:25 Setup.config
-rw-r--r--@ 1 root  admin    18K Feb 26 12:25 Setup
-rw-r--r--  1 root  admin    42K Feb 26 12:25 Makefile
lrwxr-xr-x 1 root admin 15B Feb 26 12:25 libpython2.6.a@ - > ../../../Python


I tried changing the name of the library to something else more unique
and manually ran the link line (outside of bjam), and I *can* link to
it, so that's not the problem. Why isn't it choosing the -L selected
libpython2.6.a? Or maybe I'm doing something else wrong. Or maybe it's
Apple's fault, or maybe I need to update boost from 1.40.


amos.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to