3

Mountain Lion 10.8 で xcode 4.5 を使用して opencv を使用するプロジェクトをコンパイルしようとしています。このリンクの手順に厳密に従いました。

OS X Lion / Mountain Lion 用の OpenCV (2.3.1+) を 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 でプロジェクトをビルドするための正確な手順を教えてください。

4

3 に答える 3

2

コードにアクセスできないため、これが完全な修正になるかどうかはわかりませんが、「no member named...」というコンパイル エラーを解決するには、「/opt/local/lib」を代わりに使用してみてください。 「/opt/local/lib/**」は、[ヘッダー検索パス] フィールドをダブルクリックし、XCode の [ビルド設定] > [検索パス] > [ヘッダー検索パス] で [非再帰] オプションを選択します。

「ビルド設定」>「Apple LLVM コンパイラ 4.2 - 言語」>「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 に答える