0

I am having a rough time installing OpenCV on mac(OS X 10.8.4) and xcode 4.6.3.

I have tried Macports and Homebrew for the same and failed and not even close anywhere to run it. Error usually is 'Error: Failed to install bzip2' or 'Error: Processing of port opencv failed'. I am behind a proxy and that might be a problem.

The easiest and most close method to completion was is: Using Cmake and then OpenCV to install using terminal. Then using xcode as shown at http://sadeepj.blogspot.in/2012/03/installing-and-configuring-opencv-to.html but the problem is occurred while building project in xcode I set the value of Header Search Paths to /usr/local/include and even added these 2 files 'libopencv_core.2.4.5.dylib & libopencv_highgui.2.4.5.dylib' to project.

Main.cpp file

   #include <iostream>
   #include <opencv2/opencv.hpp>

   using namespace std;
   using namespace cv;

   int main (int argc, const char * argv[])
   {
       Mat img = imread("/Users/mhtgwl/Desktop/baba.jpg"); //Change the image path here.
       if (img.data == 0) {
           cerr << "Image not found!" << endl;
           return -1;
       }
       namedWindow("image", CV_WINDOW_AUTOSIZE);
       imshow("image", img);
       waitKey();
   }

The error is "ld: library not found for -lopencv_core.2.4.5 clang: error: linker command failed with exit code 1 (use -v to see invocation)" and I have tried changing OS target version and changing library search path to /usr/local/include but it does not help.

1
  • @Totoro Sorry, it was 'libopencv_core.2.4.5.dylib & libopencv_highgui.2.4.5.dylib'. And I checked it is installed in /usr/local/lib Commented Jul 11, 2013 at 9:47

3 Answers 3

4

If you use default settings, opencv files will be inside /usr/local/lib and /usr/local/include, there should be no doubt about that.

For Xcode settings, I use:

  1. create command line tool project.
  2. add code as you did.
  3. add lib files, right click your project name, select "Add files to..", when the new dialog window appears, press key "/", then input "/usr/local/lib", select dylib files as you need (I select all for simplicity).
  4. add lib: double click you project name for project settings, in "Build Settings", add "/usr/local/lib" (recursive) for "Library Search Paths".
  5. add header: add “/usr/local/include” (non-recursive) for "Header Search Paths"
  6. also in "Build Settings" tab, filter by "c++ standard library", and set this parameter to libstdc++ (GNU C++ standard library).

If you follow all these steps carefully I am sure your code will run.

Sign up to request clarification or add additional context in comments.

2 Comments

As you said, the code ran. But it showed an error-"dyld: Library not loaded: cv2.so Referenced from: /Users/mhtgwl/Library/Developer/Xcode/DerivedData/test-feqvdmafymucqibnfkvbscgmyjip/Build/Products/Debug/test Reason: image not found (lldb)". If you could help me with this also, I would be very grateful.
I regularly write and run code with the settings similar to those given in this answer, and have no error. Just wondering why the error mentions "cv2.so" - a static library - when dylib files are already added.
0

While you have added 'libopencv_core.2.3.1.dylib & libopencv_highgui.2.3.1.dylib' to the project, the linker is looking for -lopencv_core.2.4.5 (libopencv_core.2.4.5.dylib, etc, etc.). Your computer might have an older version of Opencv installed at /usr/local/lib. Try looking for the version 2.4.5 and adding those files to the project.

For OS X 10.8, the lib files might get installed at /opt/local/lib instead of /usr/local/lib. This depends on the method of installation you selected.

1 Comment

Sorry, it was 'libopencv_core.2.4.5.dylib & libopencv_highgui.2.4.5.dylib'. And I checked it is installed in /usr/local/lib
0

I had the same problem earlier. What you need to do is not including the two directoriers "pkgconfig' and 'python2.7' when you add the dylib files to the project. It seems that cv2.so is a file in python2.7 directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.