Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV (master) - Cuda 5.5 - OS X 10.9 -- Python - malformed mach-o image

Hi

Summary

I've built OpenCV from GitHub (3.0-ocl-tp2-73-g511e79a) on OS X 10.9.1 with Cuda 5.5.28 and Python bindings (2.7.6).

However, when I attempt to import cv2 in Python, I get an ImportError with description malformed mach-o image: load command #52 length (1) would exceed sizeofcmds (5520) in /usr/local/opencv/lib/libopencv_highgui.3.0.dylib.

Does someone know what I need to do to fix this?

More Details

I've managed to install OpenCV (Git master branch Commit #g511e79a since 2.4.8 wasn't compiling for me). When building it, the following mods were made to the configuration:

  • CUDA_HOST_COMPILER: /usr/bin/clang
  • CMAKE_CXX_COMPILER: /usr/bin/c++
  • CMAKE_CXX_FLAGS: -fno_inline -stdlib=libstdc++
  • CMAKE_C_COMPILER: /usr/bin/cc
  • CMAKE_EXE_LINKER_FLAGS: -stdlib=libstdc++
  • PYTHON_EXECUTABLE: /usr/local/bin/python2.7
  • PYTHON_INCLUDE_DIR: /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Headers
  • PYTHON_LIBRARY: /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
  • PYTHON_PACKAGES_PATH: /usr/local/lib/python2.7/site-packages

The build completed fine (apart from lots of warning). However, when I ran make install a list of problematic warnings was produced. These were in the form:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: object: /usr/local/opencv/bin/opencv_haartraining malformed object (load command 37 cmdsize is zero)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: object: /usr/local/opencv/bin/opencv_haartraining malformed object (load command 37 cmdsize is zero)
-- Installing: /usr/local/opencv/bin/opencv_createsamples
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: object: /usr/local/opencv/bin/opencv_createsamples malformed object (load command 37 cmdsize is zero)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: object: /usr/local/opencv/bin/opencv_createsamples malformed object (load command 37 cmdsize is zero)
...

When I run the Python terminal and import cv2, the following occurs:

Python 2.7.6 (default, Nov 24 2013, 23:47:05)
Type "copyright", "credits" or "license" for more information.

IPython 1.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import cv2
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-72fbbcfe2587> in <module>()
----> 1 import cv2

ImportError: dlopen(/usr/local/lib/python2.7/site-packages/cv2.so, 2): Library not loaded: lib/libopencv_highgui.3.0.dylib
  Referenced from: /usr/local/lib/python2.7/site-packages/cv2.so
  Reason: no suitable image found.  Did find:
    /usr/local/opencv/lib/libopencv_highgui.3.0.dylib: malformed mach-o image: load command #52 length (1) would exceed sizeofcmds (5520) in /usr/local/opencv/lib/libopencv_highgui.3.0.dylib

I have checked the architecture of these modules, and they all report x86:

$ lipo -info /usr/local/lib/python2.7/site-packages/cv2.so
Non-fat file: /usr/local/lib/python2.7/site-packages/cv2.so is architecture: x86_64
$ lipo -info /usr/local/opencv/lib/libopencv_highgui.3.0.dylib
Non-fat file: /usr/local/opencv/lib/libopencv_highgui.3.0.dylib is architecture: x86_64
$ which python
/usr/local/bin/python
$ lipo -info /usr/local/bin/python
Non-fat file: /usr/local/bin/python is architecture: x86_64

Does anyone know what the issue is and how I can rectify it?

Thanks!