خطأ OpenCV C ++ في Xcode
سؤال
لقد بنيت مكتبات OpenCV باستخدام cmake
بناء النظام كما هو موضح هنا وقد أضافت الرأس ".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
المحلول
تجنب استخدام Xcode مع OpenCV 2.0. إذا كان استخدام OpenCV استخدم Windows وكذلك استخدام OpenCV 1.1. سوف ينقذ الكثير من الصداع. عندما يتم توثيق 2.0 / Mac بشكل أفضل ثم الانتقال إلى إصدار منصة Mac / 2.0. الكتاب (أورايلي) جيد - يغطي V1.1. يجب اتباع الدفعة التالية ل 2.0 قريبا. 1.
نصائح أخرى
بادئ ذي بدء، لا تبني Libs مع CMAKE، من الأفضل الحصول عليها من 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;
}