2009-12-03 97 views
1

我已經使用cmake構建系統構建了OpenCV庫,如here所述,並已將頭文件'.a'和'.dylib'添加到我的終端C++項目中。但是,當我運行下面的代碼(從http://iphone-cocoa-objectivec.blogspot.com/2009/01/using-opencv-for-mac-os-in-xcode.html得到它),它給了我下面的錯誤。有沒有人有任何建議?任何幫助都感激不盡。Xcode中的OpenCV C++錯誤

#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; 
} 

錯誤使用的Xcode用的OpenCV 2.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 

回答

0

避免。如果使用OpenCV,則使用Windows並使用OpenCV 1.1。這將節省很多頭痛。當2.0/Mac更好地記錄時,然後轉換到Mac平臺/ 2.0版本。這本書(O'Reilly)很好 - 封面v1.1。接下來的2.0版應該會很快推出。 1.

0

首先,沒有建立與C進行庫,更好地從MacPorts的讓他們在Mac上, 您可以輕鬆地升級到了一個班輪新版本...

加,如果你使用cv::Mat接口
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>事情會更好......;)包括在他們的名字末尾的版本的dylib庫。 (我認爲的版本少dylibs是舊接口的#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; 
}