1

我已经使用此处cmake描述的构建系统构建了 OpenCV 库,并将标头、“.a”和“.dylib”文件添加到我的终端 c++ 项目中。但是,当我运行下面的代码时(从http://iphone-cocoa-objectivec.blogspot.com/2009/01/using-opencv-for-mac-os-in-xcode.html获得),它给了我下面的错误。有没有人有任何建议?任何帮助都感激不尽。

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main()
{

    //get the image from the directed path
    IplImage* img = cvLoadImage("/Users/somedir/Programming/TestProj/fruits.jpg", 1);

    //create a window to display the image
    cvNamedWindow("picture", 1);

    //show the image in the window
    cvShowImage("picture", img);

    //wait for the user to hit a key
    cvWaitKey(0);

    //delete the image and window
    cvReleaseImage(&img);
    cvDestroyWindow("picture");

    //return
    return 0;
}

错误

Undefined symbols:
  "_cvLoadImage", referenced from:
      _main in main.o
  "_cvNamedWindow", referenced from:
      _main in main.o
  "_cvReleaseImage", referenced from:
      _main in main.o
  "_cvShowImage", referenced from:
      _main in main.o
  "_cvDestroyWindow", referenced from:
      _main in main.o
  "_cvWaitKey", referenced from:
      _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
4

2 回答 2

0

避免将 Xcode 与 OpenCV 2.0 一起使用。如果使用 OpenCV,请使用 Windows 并使用 OpenCV 1.1。它会省去很多头痛。当 2.0/Mac 的文档更好时,然后过渡到 Mac 平台/2.0 版本。这本书(O'Reilly)很好 - 涵盖 v1.1。2.0 的下一部分应该很快就会发布。1.

于 2009-12-06T00:48:50.270 回答
0

首先,不要使用 CMake 构建库,最好从 mac 上的 macports 获取它们,您可以使用单行轻松更新到较新版本...

另外,如果您使用cv::Mat接口,
#include <opencv2/core/core.hpp>事情#include <opencv2/highgui/highgui.hpp>会变得更好...... ;) 在名称末尾包含带有版本的 dylib 库。(我认为无版本的 dylib 用于旧接口#include)

对于初学者:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{

    //get the image from the directed path
    Mat img = loadImage("/Users/somedir/Programming/TestProj/fruits.jpg");

    //show the image in the window
    imshow("picture", img);

    //wait for the user to hit a key
    waitKey(0);
    //delete the image and window (automatic)
    return 0;
}
于 2012-11-02T10:00:11.773 回答