3

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

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

这是我遵循的顺序;

  • 使用端口安装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 上构建项目的确切步骤吗?

4

3 回答 3

2

如果无法访问您的代码,我不能说这是否是一个完整的修复,但是为了解决您的“没有名为...的成员”编译错误,您可以尝试将“/opt/local/lib”替换为“/opt/local/lib/**”通过双击“头文件搜索路径”字段并在 XCode 的“构建设置”>“搜索路径”>“头文件搜索路径”下选择“非递归”选项。

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

于 2013-02-15T02:26:16.093 回答
1

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

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

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

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

于 2012-12-18T13:44:40.917 回答
0

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

于 2012-12-18T13:46:37.217 回答