3

Following is my step:

1)create a command line tool project "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"

3)add "/usr/local/include" to project's Header Search Path

4)type this program:

#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

1 Answer 1

5

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:

Search paths: Search paths

Link to libraries: Linked libraries

5
  • Yes!Thank you! BTW, the latest opencv version is 2.4.2, why your version is 2.4.9?
    – HanXu
    Jul 31, 2012 at 1:37
  • I did git clone git://code.opencv.org/opencv.git yesterday and that's what wound up in /usr/local/lib.
    – SSteve
    Jul 31, 2012 at 3:49
  • Hi guys, I realise that this is very old now but I haven't really been able to find any documentation which is clear enough on how to set up openCV.framework to compile with iOS. I've added the link to the binary OpenCV.framework and added the header and library search paths. I've been looking around and I haven't been able to fix this for a couple of days. I don't know what I've missed. Can anyone help me? Apr 6, 2016 at 16:01
  • @AlecGamble: Just follow the above steps in adding the search paths and also adding the opencv libraries to the project and it should work fine. I just did it in a project.
    – swathis
    Apr 25, 2016 at 14:36
  • @ssteve You have saved my day :)
    – skyler
    Aug 3, 2017 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.