OpenCV 的 Python - OS X

4 投票
3 回答
3373 浏览
提问于 2025-04-11 19:53

我在OS X 10.5(英特尔版)上构建OpenCV时遇到了以下错误:

ld: warning in .libs/_cv_la-_cv.o, file is not of required architecture
ld: warning in .libs/_cv_la-error.o, file is not of required architecture
ld: warning in .libs/_cv_la-pyhelpers.o, file is not of required architecture
ld: warning in .libs/_cv_la-cvshadow.o, file is not of required architecture
ld: warning in ../../../cv/src/.libs/libcv.dylib, file is not of required architecture
ld: warning in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libcxcore.dylib, file is not of required architecture
Undefined symbols for architecture i386:
"_fputs$UNIX2003", referenced from:
  _PySwigObject_print in _cv_la-_cv.o
  _PySwigPacked_print in _cv_la-_cv.o
  _PySwigPacked_print in _cv_la-_cv.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
lipo: can't open input file: /var/folders/Sr/Srq9N4R8Hr82xeFvW3o-uk+++TI/-Tmp-//cchT0WVX.out (No such file or directory)
make[4]: *** [_cv.la] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

在运行命令 ./configure --without-python 时,一切正常。另一个奇怪的事情是,当我使用Python 2.4.5或2.5.1时,构建都没问题,但在切换到Python Framework 2.5.2后就出现了问题。

3 个回答

0

/Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib 其实只是指向 /usr/local/lib 的一个链接。

在删除了导致警告的文件后,我得到了:

ld: warning in .libs/_cv_la-_cv.o, file is not of required architecture
ld: warning in .libs/_cv_la-error.o, file is not of required architecture
ld: warning in .libs/_cv_la-pyhelpers.o, file is not of required architecture
ld: warning in .libs/_cv_la-cvshadow.o, file is not of required architecture
ld: warning in ../../../cv/src/.libs/libcv.dylib, file is not of required architecture
ld: warning in /Users/Pietras/opencv/cxcore/src/.libs/libcxcore.dylib, file is not of required architecture
Undefined symbols for architecture i386: ... `

这些文件是通过 make 命令创建的。

gcc: i686-apple-darwin9-gcc-4.0.1

$PATH:

/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/AVRMacPack/bin:/usr/X11R6/bin

XCode 3(最新版本)

Python 2.5.1(r251:54869,2007年4月18日,22:08:04) - 这是从 python.org 下载的 MacPython(我尝试降级使用这个版本,而不是 2.5.2,但现在不再有效了……)

which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python

我没有找到适用于 OS X 的 Python OpenCV 二进制文件。我尝试将 macports 中的 python2.4 或 2.5 设置为默认,然后编译和安装,但在尝试导入时出现了总线错误或者致命的 Python 错误,提示解释器未初始化(版本不匹配?),然后程序就退出了。

1

在链接的时候,看到它在找 /Developer/SDKs/MacOSX10.4u.sdk 这个文件时,居然警告说架构不一样,这有点奇怪。你能多说说你的构建环境吗?比如你用的 XCode 版本、GCC 版本、Python 版本,还有你的 $PATH 等等。

另外,难道你用的 OpenCV 的二进制文件都不适合你吗?

0

好的,我大概弄明白了

这个需要通过macports或者其他方式用python编译。然后我需要运行 /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 (这是我之前的python版本),在这里OpenCV就能正常工作了。

撰写回答