【问题标题】:Why can't I compile this command-line OpenCV Mac application?为什么我不能编译这个命令行 OpenCV Mac 应用程序?
【发布时间】:2012-07-28 10:27:57
【问题描述】:

以下是我的步骤:

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

但是,我得到错误:

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

【问题讨论】:

    标签: xcode macos opencv


    【解决方案1】:

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

    搜索路径:

    图书馆链接:

    【讨论】:

    • 好的!谢谢! BTW,最新的opencv版本是2.4.2,为什么你的版本是2.4.9?
    • 我昨天做了git clone git://code.opencv.org/opencv.git,这就是/usr/local/lib中的结果。
    • 大家好,我意识到这已经很老了,但我真的找不到任何足够清楚的文档来说明如何设置 openCV.framework 以与 iOS 一起编译。我添加了二进制 OpenCV.framework 的链接,并添加了头文件和库搜索路径。我一直在环顾四周,几天来一直无法解决这个问题。我不知道我错过了什么。谁能帮帮我?
    • @AlecGamble:只需按照上述步骤添加搜索路径并将opencv库添加到项目中,它应该可以正常工作。我只是在一个项目中做到了。
    • @ssteve 你拯救了我的一天 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    相关资源
    最近更新 更多