Mac上的Opencv包含错误

时间:2012-09-26 19:42:20

标签: c++ macos opencv include

我使用mac端口在mac山狮上安装了opencv。然后我写了一个OpenCV_util.cc文件:

#include <cv.h>
#include <cvaux.h>
#include <highgui.h>

当我尝试用g++ OpenCV_util.cc编译它时,我收到以下错误:

OpenCV_util.h:1:16: error: cv.h: No such file or directory
OpenCV_util.h:2:19: error: cvaux.h: No such file or directory
OpenCV_util.h:3:21: error: highgui.h: No such file or directory

然后我用了

g++ OpenCV_util.cc -I /opt/local/include/opencv -L /opt/local/lib

编译器找到了cv.h,cvaux.h和highgui.h。 但是,我收到以下错误:

In file included from OpenCV_util.h:1,
                 from OpenCV_util.cc:1:
/opt/local/include/opencv/cv.h:63:33: error: opencv2/core/core_c.h: No such file or directory
/opt/local/include/opencv/cv.h:64:33: error: opencv2/core/core.hpp: No such file or directory

......(很多像这样的错误)

我检查了/ opt / local / include / opencv2 / core /,所有文件都在那里。我认为这是因为在cv.h中,它有:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"

但不是绝对路径。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

我认为你不应该包括/opt/local/include/opencv。您可能只应使用此路径:/opt/local/include/并在使用#include时根据需要使用opencv或opencv2 例如

#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>

等等:

g++ OpenCV_util.cc -I /opt/local/include/ -L /opt/local/lib