Ask Your Question

Revision history [back]

OpenCV on OSX Mavericks in Xcode

I'm trying to run OpenCV on OSX in Xcode. I have downloaded the code from github. And used cmake to compile it.

Next I created a new Xcode project with the following code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread("img.jpg");   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window

    return 0;
}

Next I've set the header search path to: /usr/local/include

After that I've added the libraries from /usr/local/lib in the "Build Phases" as seen in the screenshot below.

image description

However, when I try to run I get the following error:

ld: library not found for -lopencv_core.3.0.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Did I mis something?

OpenCV on OSX Mavericks in Xcode

I'm trying to run OpenCV on OSX in Xcode. I have downloaded the code from github. And used cmake to compile it.

Next I created a new Xcode project with the following code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread("img.jpg");   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window

    return 0;
}

Next I've set the header search path to: /usr/local/include

After that I've added the libraries from /usr/local/lib in the "Build Phases" as seen in the screenshot below.

image description

However, when I try to run I get the following error:

ld: library not found for -lopencv_core.3.0.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Did I mis something?

edit:

Looks like i've got to add the library search path too. Now it compiles (doesn't show anything, but it compiles).