Ask Your Question
2

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

asked 2014-02-12 17:34:10 -0600

gciding gravatar 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 ...
(more)
edit retag flag offensive close merge delete

Comments

Have you found a solution for this? I am having same problem

nourani gravatar imagenourani ( 2014-03-14 01:42:19 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-03-19 18:57:18 -0600

kamjagin gravatar image

updated 2014-03-19 18:58:40 -0600

I had the same problem. It seems that cmake 2.8.12.2 corrupts the libs during rpath modification (throwing in two identical LC_RPATHs.)

Two different (but similar :) ) solutions:

  1. Downgrading cmake (I tested 2.8.11.2 and it works).
  2. Although I haven't tested this, it is likely that the problem can also be solved by upgrading to a cmake version after this commit: http://cmake.org/gitweb?p=cmake.git;a=commit;h=08141a5
edit flag offensive delete link more

Comments

Can confirm problem with cmake 2.8.12.1 as well as second solution (i built a snapshot version, see Mac OS X section here: http://www.dm9.se/?page_id=149 )

sluggo gravatar imagesluggo ( 2014-03-31 19:44:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-02-12 17:34:10 -0600

Seen: 847 times

Last updated: Mar 31 '14