为什么我不能编译这个命令行OpenCV Mac应用程序?

Han*_*nXu 3 macos xcode opencv

以下是我的步骤:

1)创建命令行工具项目"OpenCV"

2)将文件添加到项目中,该文件位于/ usr/local/lib中,后缀为2.4.2,例如"libopencv_calib3d.2.4.2.dylib"

3)将"/ usr/local/include"添加到项目的标题搜索路径中

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;
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

ld: library not found for -lopencv_calib3d.2.4.2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

问题出在哪儿?

我正在使用山狮和Xcode 4.4

SSt*_*eve 5

您不需要将opencv库添加到项目中,但您需要链接到库并设置库搜索路径.我能够使用以下设置编译和运行您的程序:

搜索路径: 搜索路径

链接到图书馆: 链接库