在Xcode 4.5上安装OpenCV 2.4.3

3

我正在尝试使用 Xcode 4.5 在 Mountain Lion 10.8 上编译一个使用 OpenCV 的项目,我严格遵循了此链接上的步骤:

在 OS X Lion / Mountain Lion 上使用 Xcode 编译 OpenCV (2.3.1+)

这是我遵循的步骤:

  • 使用 ports 安装 opencv:sudo port install opencv configure.compiler = llvm-gcc-4.2
  • 打开 Xcode 并创建一个新项目(使用 c++ 命令行应用程序)。
  • 将“/opt/local/lib/**”路径添加到“库搜索路径”中
  • 将任何 libopencv_. Dylib 添加到一个新组中
  • 将“/opt/local/include/**”路径添加到“头文件搜索路径”中

每次我尝试编译时,Xcode 都会失败并出现以下错误:

In file included from /Users/oliver/OpenCVHelloWorld/main.cpp:12:
In file included from /opt/local/include/opencv2/opencv.hpp:46:
In file included from /opt/local/include/opencv2/core/core_c.h:47:
/opt/local/include/opencv2/core/types_c.h:322:17: error: use of undeclared identifier 'lrint'
    return (int)lrint(value);
                ^
/opt/local/include/opencv2/core/types_c.h:742:5: error: use of undeclared identifier 'assert'
    assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
    ^
/opt/local/include/opencv2/core/types_c.h:773:5: error: use of undeclared identifier 'assert'
    assert( (unsigned)row < (unsigned)mat->rows &&
    ^
/opt/local/include/opencv2/core/types_c.h:780:9: error: use of undeclared identifier 'assert'
        assert( type == CV_64FC1 );
        ^
/opt/local/include/opencv2/core/types_c.h:790:5: error: use of undeclared identifier 'assert'
    assert( (unsigned)row < (unsigned)mat->rows &&
    ^
/opt/local/include/opencv2/core/types_c.h:797:9: error: use of undeclared identifier 'assert'
        assert( type == CV_64FC1 );
        ^
In file included from /Users/oliver/OpenCVHelloWorld/main.cpp:12:
In file included from /opt/local/include/opencv2/opencv.hpp:46:
/opt/local/include/opencv2/core/core_c.h:1118:5: error: use of undeclared identifier 'assert'
    assert( _elem->flags >= 0 /*&& (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total*/ );
    ^
In file included from /Users/oliver/OpenCVHelloWorld/main.cpp:12:
In file included from /opt/local/include/opencv2/opencv.hpp:47:
In file included from /opt/local/include/opencv2/core/core.hpp:56:
In file included from /usr/include/c++/4.2.1/algorithm:64:
In file included from /usr/include/c++/4.2.1/bits/stl_algobase.h:70:
In file included from /usr/include/c++/4.2.1/iosfwd:44:
/usr/include/c++/4.2.1/bits/c++locale.h:76:5: error: use of undeclared identifier 'va_start'
    va_start(__args, __fmt);
    ^
/usr/include/c++/4.2.1/bits/c++locale.h:84:5: error: use of undeclared identifier 'va_end'
    va_end(__args);
    ^
/usr/include/c++/4.2.1/cstdarg:54:20: note: expanded from macro 'va_end'
#define va_end(ap) va_end (ap)
                   ^
In file included from /Users/oliver/OpenCVHelloWorld/main.cpp:12:
In file included from /opt/local/include/opencv2/opencv.hpp:47:
In file included from /opt/local/include/opencv2/core/core.hpp:56:
In file included from /usr/include/c++/4.2.1/algorithm:64:
In file included from /usr/include/c++/4.2.1/bits/stl_algobase.h:70:
In file included from /usr/include/c++/4.2.1/iosfwd:48:
In file included from /usr/include/c++/4.2.1/bits/postypes.h:45:
In file included from /usr/include/c++/4.2.1/cwchar:51:
/usr/include/c++/4.2.1/ctime:65:11: error: no member named 'clock_t' in the global namespace
  using ::clock_t;
        ~~^
/usr/include/c++/4.2.1/ctime:67:11: error: no member named 'tm' in the global namespace
  using ::tm;
        ~~^
/usr/include/c++/4.2.1/ctime:69:11: error: no member named 'clock' in the global namespace
  using ::clock;
        ~~^
/usr/include/c++/4.2.1/ctime:70:11: error: no member named 'difftime' in the global namespace
  using ::difftime;
        ~~^
/usr/include/c++/4.2.1/ctime:71:11: error: no member named 'mktime' in the global namespace
  using ::mktime;
        ~~^
/usr/include/c++/4.2.1/ctime:72:11: error: no member named 'time' in the global namespace
  using ::time;
        ~~^
/usr/include/c++/4.2.1/ctime:73:11: error: no member named 'asctime' in the global namespace
  using ::asctime;
        ~~^
/usr/include/c++/4.2.1/ctime:74:11: error: no member named 'ctime' in the global namespace
  using ::ctime;
        ~~^
/usr/include/c++/4.2.1/ctime:75:11: error: no member named 'gmtime' in the global namespace
  using ::gmtime;
        ~~^
/usr/include/c++/4.2.1/ctime:76:11: error: no member named 'localtime' in the global namespace
  using ::localtime;
        ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

我也尝试更改编译器为LLVM GCC 4.2编译器,但没有成功。有人能告诉我在xcode中使用opencv Mountain Lion和Xcode 4.5构建项目的确切步骤吗?


你尝试编译的代码是什么?你使用了C++11扩展吗? - Barney Szabolcs
请查看这篇文章:http://stackoverflow.com/questions/13564289/osx-10-7-5-opencv-2-4-3-undefined-symbols-for-architecture-x86-64-when-usin/14032179#14032179 - RezA
3个回答

2
没有代码的访问权限,我无法确定这是否是完整的修复方法,但为了解决“no member named...”编译错误,您可以尝试通过双击“Header Search Paths”字段并在XCode的“Build Settings”>“Search Paths”>“Header Search Paths”下选择“non-recursive”选项,将“/opt/local/lib**”替换为“/opt/local/lib”。
您还可以尝试在导航到“Build Settings”>“Apple LLVM compiler 4.2 - Language”>“C++ Standard Library”后重新编译,并选择“libstdc++(GNU C ++标准库)”,而不是XCode 4.5的默认“libc++(带有C ++11支持的LLVM C ++标准库)”。

1

我会使用不同的安装命令:

sudo port install tbb
sudo port install opencv +debug +eigen +python27 +qt4 +tbb 

Eigen和Qt4是可选的,但TBB是非常重要的,因为OpenCV在有TBB时大量使用多线程技术。换句话说,没有TBB,OpenCV会慢很多。

我不会手动指定编译器,因为我记得这对我来说行不通。


第二个端口安装命令似乎需要在其参数之间添加空格。例如:“sudo port install opencv +debug +eigen +python27 +qt4 +tbb”。 - Gökhan Barış Aker

0

确保它被编译为C++,将您的m文件重命名为mm


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接