我正在尝试使用Mountain Lion 10.8上的xcode 4.5编译一个使用opencv的项目,我密切关注此链接上的过程:
Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode
这是我遵循的顺序;
每次我尝试编译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上构建项目的确切步骤吗?
答案 0 :(得分:2)
如果无法访问您的代码,我无法说明这是否是一个完整的解决方案,但是,为了解决您的问题而没有一个名为......&#34;编译错误,您可以尝试替换&#34; / opt / local / lib&#34; for&#34; / opt / local / lib / **&#34;通过双击&#34;标题搜索路径&#34;字段并选择&#34;非递归&#34; XCode&#34;构建设置&#34;下的选项&GT; &#34;搜索路径&#34; &GT; &#34;标题搜索路径&#34;。
您还可以在导航到&#34;构建设置&#34;之后尝试重新编译。 &GT; &#34; Apple LLVM编译器4.2 - 语言&#34; &GT; &#34; C ++标准库&#34;,并选择&#34; libstdc ++(GNU C ++标准库)&#34;而不是XCode 4.5的默认&#34; libc ++(支持C ++ 11的LLVM C ++标准库)&#34;。
答案 1 :(得分:1)
我会使用不同的安装命令:
sudo port install tbb
sudo port install opencv +debug +eigen +python27 +qt4 +tbb
eigen和qt4是可选的,tbb是相当必要的,因为opencv在存在时大量使用tbb进行多线程处理。换句话说,没有tbb,opencv要慢得多。
我不会手动指定编译器。我记得那对我不起作用。
答案 2 :(得分:0)
确保将其编译为c ++,将m文件重命名为mm