I've taken a library that is distributed as a binary lib (.a) and header, written some c++ code against it, and want to wrap the results up in a python module.
I've done this here.
The problem is that when importing this module on Mac OSX (I've tried 10.5 and 10.6), I get the following error:
dlopen(/Library/Python/2.5/site-packages/dirac.so, 2): Symbol not found: _DisposePtr
Referenced from: /Library/Python/2.5/site-packages/dirac.so
Expected in: dynamic lookup
This looks like symbols defined in the Carbon framework aren't being properly resolved, but I'm not sure what to do about that. I am supplying -framework Carbon to distutil.core.Extension's extra_link_args parameter, so I'm not sure what else I should do.
Any help would be much appreciated.
Update:
The compile line generated by setup.py looks like this:
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -Isource -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/numarray/numpy -I/usr/lib/python/2.5/site-packages/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c source/Dirac_LE.cpp -o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o
The linker line looks like this:
g++ -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc build/temp.macosx-10.5-i386-2.5/diracmodule.o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o -Llibs/MacOSX -lDiracLE -o build/lib.macosx-10.5-i386-2.5/dirac.so -framework Carbon
otool reports:
dirac.so:
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.5)
Update 2:
On MacOS 10.5, modifying the dlopen flags from the default of RTLD_NOW to RTLD_LAZY solves the problem. However, this does not work on Mac OS 10.6.
On 10.6, the following sequence allows the library to run properly, although I'm not sure why:
python setup.py build -v
run the linker line (printed to console by setup.py) again, manually.
python setup.py install
I'm still looking for a good answer as to how to get this to work properly. Thanks!
You're going to kick yourself when you see the answer to this! Try changing this:
link_args = ['-framework Carbon'] if platform == 'Darwin' else []
to this:
link_args = ['-framework', 'Carbon'] if platform == 'Darwin' else []
Once I made this change I was able to do a clean build and import the module straight away :)
Related
I am trying to instal Kivy by following the instructions on this page.
I already installed Cython and Pygame, yet when I try to install Kivy from the command line the following error appears before the code stops executing:
/usr/bin/clang -bundle -undefined dynamic_lookup -g build/temp.macosx-10.6-intel-
2.7/kivy/graphics/texture.o -o
/Applications/Kivy.app/Contents/Resources/kivy/kivy/graphics/texture.so -
F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/
Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks -framework OpenGL
-arch x86_64 -lm
Any idea what might be causing this? I can post more details of the error if necessary. Thanks.
I am tying to build PIL 1.1.7 on Mac OS X 10.7, I am getting this error:
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/opt/local/include -I/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _imaging.c -o build/temp.macosx-10.3-fat-2.6/_imaging.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1
I have the latest Xcode installed. gcc-4.0 does not exist but gcc-4.2 does. I don't know why it's trying to use gcc-4.0.
You appear to be using a 32-bit-only Python possibly one downloaded from python.org. They are built with gcc-4.0 and for the i386 and ppc archs for compatibility with multiple OS X versions. When building a C extension module, Python's Distutils will attempt to use the same compiler version and options that Python itself was build with. Because gcc-4.0 and support for the ppc architecture are no longer included with Xcode 4 and OS X 10.7, you should not use the 32-bit-only builds on 10.7 if you need to build extension modules. Either install a 64-bit/32-bit version of Python (2.7.2 and 3.2.2 are current from python.org) or use the Apple-supplied system Pythons in 10.7 (/usr/bin/python which defaults to 2.7.1).
I use Python on Mac OS X version 10.6. I recently installed the newest Mac OS X developer tools SDK, which has GCC in it. The SDKs I have are:
$ ls /Developer/SDKs/
MacOSX10.4u.sdk MacOSX10.5.sdk MacOSX10.6.sdk
I'd like to use Mac OS X 10.6 with Python/distutils, whenever I install a python package with "setup.py install" that requires compilation.
I notice that Python passes the -isysroot flags and paths to Mac OS X 10.5 (not 10.6), i.e.:
$ python-config --cflags --ldflags
-I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.0/include
-L/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/config -ldl -framework CoreFoundation -lpython2.7 EPD64.framework/Versions/7.0/Python
How can I correct this? I'd like it to use the 10.6 SDK instead.
Right now when I run "python setup.py install" on a package that requires C compilation, it yields calls to GCC that look like this:
gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.0/include -DHAVE_RINTF=1 -DHAVE_FINITE=1 -DHAVE_EXPM1=1 -DHAVE_RINT=1 -DHAVE_LOG2=1 -DHAVE_LOGBL=1 -DHAVE_SNPRINTF=1 -DHAVE_LOG1P=1 -DHAVE_ROUND=1 -DHAVE_FMIN=1 -Iinclude -Isrc/lapack -Isrc/f2c -I/Library/Frameworks/EPD64.framework/Versions/7.0/include/python2.7 -c src/f2c/signal_.c -o build/temp.macosx-10.5-x86_64-2.7/src/f2c/signal_.o
which calls 10.5 SDKs in its path.
I use the Enthought Python Distribution installation of Python in case that makes a difference.
Thanks very much.
It's a feature and should not cause you any worries. Distutils does this deliberately to ensure that C extension modules that you build are built the same way that the Python interpreter in use was built. Extensions built this way are upwards compatible: they will work on 10.6 as well. If you absolutely want to use 10.6 ABI features, you should use a Python that was built using the 10.6 SDK, for instance, from a recent python.org 64-bit installer or from MacPorts or Homebrew.
I completely disagree with #Ned Deily
The poster obviously uses Enthought Python Distribution (EPD), and installing the whole new Python would require an installation of the whole new infrastracture.
I have the same situation. On MacBook with Mac Os X 10.6 the project (MeshPy) builds correctly, but on the Imac with Mac Os X 10.7 it does not (no 10.5 SDK is provided, and with this SDK EPD was built). You can try to install this old SDK, however, a much simpler hack (hopefully it works) is to make a symlink:
sudo ln -sf MacOSX10.6.sdk MacOSX10.5.sdk
It worked for me.
I'm trying to install MySQL_python 1.2.2 (I specifically need this version, not the current 1.2.3) on Snow Leopard, and getting this error below.
Command to install:
pip install -Iv http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/MySQL-python-1.2.2.tar.gz/download
And a portion of the trace:
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.6-universal-2.6
/usr/bin/gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,2,'final',0) - D__version__=1.2.2 -I/usr/local/mysql/include - I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
In file included from _mysql.c:35:
/usr/local/mysql/include/my_config.h:1053:1: warning: "HAVE_WCSCOLL" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:803:1: warning: this is the location of the previous definition
In file included from /usr/local/mysql/include/mysql.h:47,
from _mysql.c:40:
/usr/include/sys/types.h:92: error: duplicate ‘unsigned’
/usr/include/sys/types.h:92: error: two or more data types in declaration specifiers
error: command '/usr/bin/gcc-4.2' failed with exit status 1
Has anyone seen this error before?
A quick google search yielded this answer:
To get mysqldb working on leopard I found I had to edit _mysql.c and edit out the lines:
#ifndef uint
#define uint unsigned int
#endif
I also had to edit site.cfg and mark threadsafe to False.
After doing this, I managed to get MySQLdb to install, great! Not so
fast, there was yet another problem:
Referenced from: .../_mysql.so Reason: image not found
The solution:
sudo ln -s /usr/local/mysql/lib/ /usr/local/mysql/lib/mysql
As the error says, things have been redefined. I've gotten around this in the past by commenting out the offending declarations in the source of the library being build. That solution however has some obvious problems...
I'm trying to install matplotlib for Python on MacOS X. If I use the system Python 2.6.1, the default compiler commands that matplotlib uses (presumably via distutils) are::
gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes
g++-4.2 -Wl,-F. -bundle -undefined dynamic_lookup
However, if I simply add the python.org 2.6.6 Python to the PATH to use that instead, the default compilers suddenly change to
gcc-4.0 -DNDEBUG -g -O3
c++ -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk \
-g -bundle -undefined dynamic_lookup
This causes issues, so I was wondering what determines which C compilers are used when running python setup.py install? Why does using the python.org Python mean that different default compiler commands are used?
The python.org release is designed to work just as well on MacOsX 10.5 as on 10.6, therefore of course it has to stick with a gcc release that is commonly available for both. Apple's system Python, of course, labors under no such constraint -- it supports only a very specific version of MacOsX and therefore can use the "latest and greatest" gcc available for that one specific version... and so of course it does;-).