TheNone
TheNone

Reputation: 5802

"mach-o, but wrong architecture" in OpenCv (Leopard)

I have installed OpenCV from this doc with CMake . My ~/.profile file is :

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export ARCHFLAGS="-arch i386 -arch x86_64"
export ARCHFLAGS="-arch i386" 
export VERSIONER_PYTHON_PREFER_64_BIT=yes
export VERSIONER_PYTHON_PREFER_32_BIT=no
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH    
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib

With import cv I have this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/site-packages/cv.py", line 1, in <module>
    from cv2.cv import *
ImportError: dlopen(/usr/local/lib/python2.6/site-packages/cv2.so, 2): no suitable image found.  Did find:
    /usr/local/lib/python2.6/site-packages/cv2.so: mach-o, but wrong architecture

My python architecture:

file "$( "$(which python)" -c "import sys;print(sys.executable)" )"
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):    Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

I have read and run all answers about OpenCV and Leopard in stackoverflow but still above error. Any help about this will be appreciated.

Thanks in advance

Upvotes: 4

Views: 6013

Answers (1)

Juha
Juha

Reputation: 2115

Leopard (and snow leopard) is a crossbreed, it contains both binaries: 32bit and 64bit... and it mixes them up... and its a nightmare. To my knowledge, you cannot mix 32bit and 64bit libraries in the same running program.

I have used this hack: How to force /usr/bin/gcc -> /usr/bin/gcc -m32?

It makes everything to compile in i386 (march 32 bit). You can also force it to 64 (not recommended). It fixes a lot of other compiling issues too. Remember, that this is a hack.

Backup /usr/bin/, do the hack, compile open cv and remove the hack.

Other solution is to upgrade to lion which (so far) seems not to have 32/64 bit problems.

Helpful commands also are:

lipo -info /usr/local/lib/python2.6/site-packages/cv2.so
arch -i386 /usr/bin/python

Lipo checks the architechture of shared objects and latter How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions. Maybe you can fix this by forcing python to the same arch as cv2...

EDIT

I noticed that you are using macport cv2 and apple python. Try /opt/local/bin/python2.6 when running the code.

Upvotes: 4

Related Questions