为什么我不能编译此命令行OpenCV Mac应用程序? [英] Why can't I compile this command-line OpenCV Mac application?
问题描述
以下是我的步骤:
1)创建一个命令行工具项目"OpenCV"
1)create a command line tool project "OpenCV"
2)将文件添加到项目中的后缀为2.4.2的/usr/local/lib中,例如 "libopencv_calib3d.2.4.2.dylib"
2)add files to the project which are in /usr/local/lib with suffix 2.4.2, such as "libopencv_calib3d.2.4.2.dylib"
3)在项目的标题搜索路径中添加"/usr/local/include"
3)add "/usr/local/include" to project's Header Search Path
4)输入此程序:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp>
int main(int argc, char** argv)
{
IplImage * pInpImg = 0;
// Load an image from file - change this based on your image name
pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
fprintf(stderr, "failed to load input image\n");
return -1;
}
// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if( !cvSaveImage("my_image_copy.png", pInpImg) )
{
fprintf(stderr, "failed to write image file\n");
}
// Remember to free image memory after using it!
cvReleaseImage(&pInpImg);
return 0;
}
但是,我收到错误消息:
However, I get error :
ld: library not found for -lopencv_calib3d.2.4.2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
问题出在哪里?
我正在使用美洲狮和Xcode 4.4
I'm using mountain lion and Xcode 4.4
推荐答案
您不需要将opencv库添加到您的项目中,但是您需要链接到库并设置库搜索路径.我能够使用以下设置编译并运行您的程序:
You don't need to add the opencv libs to your project but you do need to link to the libraries and set the library search path. I was able to compile and run your program with these settings:
搜索路径:
链接到库:
这篇关于为什么我不能编译此命令行OpenCV Mac应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!