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.
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).
Why don't you use CMake for your project as well? Then you can just automatically generate a properly configured Xcode project.
I have no experience with CMake. I found somewhere that I needed it so I did. But that would be a handy feature. However it seem's i've got it working. I had to add the library search path.
CMake really shines when you have: 1) lots of third party dependencies and 2) when your code should compile and run on multiple platforms. If you only ever target OS X I can understand leaving it out, but if your project's scope grows you may want to reconsider using CMake in the future.