【问题标题】:OpenCV 2.4.3 on Xcode 4.5Xcode 4.5 上的 OpenCV 2.4.3
【发布时间】:2012-12-17 10:11:15
【问题描述】:

我正在尝试在 Mountain Lion 10.8 上使用 xcode 4.5 编译一个使用 opencv 的项目,我密切关注此链接上的过程:

Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode

这是我遵循的顺序;

  • 使用端口安装 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 编译器,但没有成功。 有人可以告诉我使用 opencv Mountain Lion 和 Xcode 4.5 在 xcode 上构建项目的确切步骤吗?

【问题讨论】:

标签: xcode opencv osx-mountain-lion


【解决方案1】:

如果无法访问您的代码,我不能说这是否是一个完整的修复,但为了解决您的“没有名为...的成员”编译错误,您可以尝试替换“/opt/local/ lib" 为 "/opt/local/lib/**" 通过双击 "Header Search Paths" 字段并在 XCode 的 "Build Settings" > "Search Paths" > "Header Search Paths" 下选择 "non-recursive" 选项”。

您也可以在导航到“构建设置”>“Apple LLVM 编译器 4.2 - 语言”>“C++ 标准库”并选择“libstdc++(GNU C++ 标准库)”而不是 XCode 4.5 的默认值后尝试重新编译libc++(支持 C++11 的 LLVM C++ 标准库)”。

【讨论】:

    【解决方案2】:

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

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

    eigen 和 qt4 是可选的,tbb 是相当必要的,因为当存在时,opencv 大量使用 tbb 进行多线程。换句话说,opencv 没有 tbb 会慢很多。

    我不会手动指定编译器。我记得这对我不起作用。

    【讨论】:

    • 第二个端口安装命令似乎在其参数之间需要空格。例如“sudo port install opencv +debug +eigen +python27 +qt4 +tbb”。
    【解决方案3】:

    确保它编译为 c++,将你的 m 文件重命名为 mm

    【讨论】:

      猜你喜欢
      • 2012-11-03
      • 2013-03-29
      • 1970-01-01
      • 2012-10-22
      • 2012-10-28
      • 2013-03-24
      • 2023-03-21
      • 2013-01-29
      • 1970-01-01
      相关资源
      最近更新 更多