简体   繁体   中英

Installing OpenCV on mac error

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM