OpenCV Clang mat.hpp错误:调用成员函数'ptr'是不明确的

时间:2013-12-16 23:11:52

标签: c++ opencv clang

我编译使用OpenCV的程序时出错,只是包含#include,即:

In file included from /usr/local/include/opencv2/highgui/highgui.hpp:46:
In file included from /usr/local/include/opencv2/core/core.hpp:4826:
/usr/local/include/opencv2/core/mat.hpp:2248:42: error: call to member function 'ptr' is ambiguous
{ return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); }
                     ~~~~~~~~~~~~~~~~~~~~^~~
/usr/local/include/opencv2/core/core.hpp:3507:12: note: candidate function
    uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
           ^
/usr/local/include/opencv2/core/core.hpp:3509:12: note: candidate function
    uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
           ^
/usr/local/include/opencv2/core/core.hpp:3513:12: note: candidate function not viable: no known conversion from 'int' to
      'const int *' for 1st argument; take the address of the argument with &
    uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
           ^
/usr/local/include/opencv2/core/core.hpp:3511:12: note: candidate function not viable: requires at least 4 arguments, but 3 were
      provided
    uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);

我尝试了多个(最近的)OpenCV版本,但在我的情况下,它们都没有工作。 OpenCV是否正式不支持Clang,或者我应该报告错误? 我使用Linux(ubuntu 13.04),我使用clang 3.2-1。

1 个答案:

答案 0 :(得分:-1)

我最近在我的Mac上遇到了同样的错误。 (一月至2016)

获取错误的过程如下:

  1. 使用brew安装opencv brew install opencv 在这种情况下,brew在opencv之前安装gcc并使用gcc NOT clang编译opencv。 gcc安装在/usr/local/Cellar/gcc/5.3.0/bin/

  2. 我制作了我的程序并尝试使用默认选项使用CMake进行编译。 cmake尝试使用clang作为编译器:它的位置是/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

  3. 因为opencv的编译器和程序的编译器不同,所以会产生错误。

  4. 所以,我试着在cmake中将编译器设置为gcc set( CMAKE_C_COMPILER /usr/local/Cellar/gcc/5.3.0/bin/gcc-5 ) set( CMAKE_CXX_COMPILER /usr/local/Cellar/gcc/5.3.0/bin/gcc-5 )

    然后,我传递了这个错误。