xcode 为什么我不能编译这个命令行 OpenCV Mac 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11726837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't I compile this command-line OpenCV Mac application?
提问by HanXu
Following is my step:
以下是我的步骤:
1)create a command line tool project "OpenCV"
1)创建一个命令行工具项目“OpenCV”
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"
2) 将/usr/local/lib 后缀为2.4.2的文件添加到项目中,例如“libopencv_calib3d.2.4.2.dylib”
3)add "/usr/local/include" to project's Header Search Path
3)将“/usr/local/include”添加到项目的标题搜索路径
4)type this program:
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)
Where is the problem?
问题出在哪儿?
I'm using mountain lion and Xcode 4.4
我正在使用山狮和 Xcode 4.4
回答by SSteve
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 库添加到您的项目中,但您需要链接到库并设置库搜索路径。我能够使用这些设置编译和运行您的程序:
Search paths:
搜索路径:
Link to libraries:
图书馆链接: