OpenCV on Mac OSX: A step-by-step guide

OpenCV on Mac OSX: A step-by-step guide
I’m using OpenCV for my 4th year design project and setting it up was a huge pain. I had to look through a whole bunch of different sites to figure out what to do. There are various ways to install it – through package managers such as Homebrew or Macports, or through the tarball + cmake. Now that I’ve got it set up, I decided to write this little post to explain to others how to go about setting it up.

Note: This method does not set up the Python bindings for OpenCV (still working on that). It only sets up the C++ framework. Also, I tested this on OSX Lion, but it should apply to Snow Leopard or Leopard. Also you will need XCode installed for any of this to work (but you knew that, right?)

On that note, let’s get started.

Download a Package Manager

It’s between Macports, Fink or Homebrew. I used Macports, so I’d recommend that. Download the .dmg file, then install it. You can check to see if it installed successfully by opening your terminal and typing port.

Download the OpenCV Tarball

You can get that fromย here. Look for the Linux or Mac version. Unzip it after you download it into a folder.

Get cmake

In your terminal, type in the following:
sudo port install cmake
This will go fetch cmake and its dependencies and install them onto your system. You can check to see that cmake is installed by typing cmake in a new terminal window.

Build OpenCV

We are going to build OpenCV using cmake. In terminal, navigate to the folder where OpenCV was extracted to. Type in the following:

# make a separate directory for building
mkdir build
cd build
cmake -G "Unix Makefiles" ..

Now, we can make OpenCV. Type the following in:

make -j8
sudo make install

This should now build OpenCV into your /usr/local/ directory.

Make A Sample OpenCV Project

So we now have OpenCV built but we still have to link to the framework in our project.

  1. Start a new XCode Command Line Tool project.
  2. We have to link the .dylib files provided by OpenCV into our project. To do this, right click on the project, and click “Add files to..”
  3. When Finder pops up, hit “/” to bring up the navigation panel.
  4. Type in /usr/local/lib
  5. Add in all the .dylib files that you need. To prevent linker errors, I recommend you initially add ALL the files ending in “…2.3.1.dylib”. There should be a dozen or so. If you know what you need, you can obviously pick and choose.
  6. Now, you should have a bunch of .dylib files in your project. Feel free to move them to a separate group within your project.
  7. Click on the project file and go to “Build Settings”.
  8. Search for “Header Search Paths”
  9. Change the path to ย /usr/local/include. This is where the header files for OpenCV were built.
  10. Open main.cpp
  11. Copy the following code snippet. This snippet should load a .jpg image and save it as a .png image.
// Example showing how to read and write images
#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);
    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!

  return 0;

And there you go. That should be working for you. If it’s not, leave a comment below with the error you get and I’ll try looking into it for you. Hopefully, this helps save you some time.

On that note, here is a good OpenCV Tutorial.

Edit: Oops,ย looks like that link is dead now. ๐Ÿ™

Please read before commenting: Hey guys – thanks a lot for all the comments on this thread. Unfortunately, it’s been a long time since I looked into OpenCV so I don’t remember the details anymore. If you have questions, skim through the comments because many people have posted their solutions. Feel free to comment if you don’t find an answer. On the other hand, if you made some small change that made this work – please add it to the comments so others can find it useful. Thanks!

  1. Hi,

    Thanks for the tutorial.

    When I try your sample, I’m getting number of errors in XCode.

    c++locale.h – Semantic issue. Use of undeclared indentifier ‘va_start’
    calib3d.hpp – Semantic issue. Use of undeclared indentifier ‘DBL_….
    contrib.hpp – Semantic issue…
    And many more.

    Any idea what’s wrong in my project?

    1. Hard to say based on those error messages. Are you compiling this project using g++? That may be one issue. What OS are you on? I tested this on Lion.

      These sound like syntax issues, so at the very least, you could go into those files and use an alternate syntax.

      1. Hi,

        I’m using Mac OS X Lion (10.7.2).

        I installed OpenCV before I found your guide. These are the steps I followed.

        1. Installed CMake
        2. tar xjf OpenCV-2.3.1a.tar.bz2
        3. cd OpenCV-2.3.1
        4. cmake -DCMAKE_INSTALL_PREFIX=/usr .
        5. make
        6. sudo make install

        OpenCV is successfully installed to /usr. And I’m able to compile your cpp file using the terminal with the following command.
        g++ -I/usr/include -L/usr/lib -lopencv_core.2.3.1 -lopencv_calib3d.2.3.1 -lopencv_imgproc.2.3.1 -lopencv_legacy.2.3.1 -lopencv_highgui.2.3.1 main.cpp

        But I can’t build/run the same cpp file with XCode. I think it’s something wrong with linking. I have set XCode’s Header Search Path to /usr/include and included dylib files from /usr/lib. But still getting the same error.

        1. I got it working. Apparently I have made a mistake by installing OpenCV at /usr. When I set Header Search Path to /usr/include XCode picks some unnecessary headers and fails to link my project it seems. I followed your tutorial from the beginning and the it worked. ๐Ÿ™‚

          Thanks for the help.

          One addition, third include in your code is redundant i guess.
          I’m able to successfully run the code without this include.


          1. Thanks Gian! Glad I could help and thanks for posting your thoughts so other readers in the same boat as you are able to figure out the issue! Cheers.

  2. when i type this: cmake -G “Unix Makefiles” ..
    i get this: CMake Error: The source directory “/Users/karansamel” does not appear to contain CMakeLists.txt.
    Specify –help for usage, or press the help button on the CMake GUI.
    are we supposed to have CMakeLists.txt in there before?

    1. actually the only problem I’m having now is at the last step when i type in sudo make install, i get this:
      make: *** No rule to make target `install’. Stop.

      1. It seems like the directory from where you are executing “sudo make install” does not have Makefiles. Can you see if Makefile exists in that directory?

  3. When I tried to type “cmake -G “Unix Makefiles” ..”
    I got this massage error
    The source directory “/Users/seereennoorwali/Desktop/OpenCV-2.4.0/build” does not appear to contain CMakeLists.txt.
    Specify –help for usage, or press the help button on the CMake GUI.

    Do you know how can I fix it ?
    Thank you

    1. It means that the directory that you are in does not have the file CMakeLists.txt Try locating that file first, and run it from its parent directory.

      1. Thanks I fix this problem ๐Ÿ˜€
        and I run the program ,,
        but there is a problem with the third include line ….
        without it the program will work well …

        1. Oh! I have the file.
          But I don’t know how to navigate to it in the terminal.
          What should I write instead of / before
          mkdir build
          cd build
          cmake -G “Unix Makefiles” .. ?

  4. hi,
    when i got this error message :
    _cvReleaseImage referenced from :
    _main in main.o
    symbol(s) not found
    collect2: id returned 1 exit status

    what was i miss ?

    1. Can’t figure out from that error log, but it looks like the cvReleaseImage method was not found. Are you including the correct header files?

  5. I have some errs when I try the last 2 commands: make -j8 and
    sudo make install
    it says:
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_cocoa.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    I don’t know what’s going on. I’m using Lion with Xcode 4.3. Could you please tell me how can I make it right?

    1. I’m sorry Natalie, not sure about that error. It looks like a build error, so my only guess would be that the download was corrupt in some way. Not sure what “error 1” and “error 2” are referring to. Any luck Googling? Try re-tracing your steps from the beginning again or downloading OpenCV again.

      1. Hey,

        I’m getting the same error as Natalie. I’ve tried to re-do everything from the beginning with no luck.

        After the command “make -j8” the terminal runs through all the building, and at about 34% of the way through, I get this message: “Undefined symbols for architecture x86_64: …” with a long list of symbols followed by the following: “ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        make[2]: *** [lib/libopencv_highgui.2.4.2.dylib] Error 1
        make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
        make: *** [all] Error 2”

        Did you guys ever figure out what was wrong?



          1. ld: symbol(s) not found for architecture x86_64
            clang: error: linker command failed with exit code 1 (use -v to see invocation)
            make[2]: *** [lib/libopencv_highgui.2.4.0.dylib] Error 1
            make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
            make: *** [all] Error 2

            This was the result for both
            make -j8
            sudo make install

          2. I recently ran into this problem too, and beat my head against a brick wall for a few hours.
            This was on a Snow Leopard install, where I had previously installed “fink” and many packages under it. I suspected that the cmake was referencing some of the 32 bit stuff I had installed, so I moved the fink sw directory out of the way (from /sw to /sw_tmp), and then completely cleaned out the mac ports and opencv stuff, started over (sudo port uninstall all). I reran the instructions starting from step 1. Success.

          3. Awesome, I’m glad you were able to figure it out. Thanks for posting it so people can learn from your experience.

  6. Thanks a lot, it did work perfectly well. I tried to do the same on a Cocoa app but I get all sorts of errors. I managed to create a .cpp file on the project with your code and compile it normally, but trying to include this cpp on my AppDelegate causes errors. Even renaming the AppDelegate.m to .mm to ensure it’s C++ causes it to fail. Any idea how to include this on a .m or .mm file?


  7. I would like to ask how can I remove the openCV from the system ?
    I tried your steps to install it … but recently I figure out that I need ffmpeg before openCV

    is there anyway to install ffmpeg after openCV … and connect both of then together
    or do I need to delete openCV then install ffmpeg then install openCV

    any suggestions?


    1. This is some new error ๐Ÿ™

      Ld /Users/Shree/Library/Developer/Xcode/DerivedData/examp-etciozbcfzozwlckbgilctoxatkh/Build/Products/Debug/examp normal x86_64
      cd /Users/Shree/Desktop/thippi/Example/examp
      /Applications/ -arch x86_64 -isysroot /Applications/ -L/Users/Shree/Library/Developer/Xcode/DerivedData/examp-etciozbcfzozwlckbgilctoxatkh/Build/Products/Debug -F/Users/Shree/Library/Developer/Xcode/DerivedData/examp-etciozbcfzozwlckbgilctoxatkh/Build/Products/Debug -filelist /Users/Shree/Library/Developer/Xcode/DerivedData/examp-etciozbcfzozwlckbgilctoxatkh/Build/Intermediates/ -mmacosx-version-min=10.8 -lopencv_core.2.4.9 -lopencv_highgui.2.4.9 -lopencv_imgproc.2.4.9 -lopencv_ml.2.4.9 -o /Users/Shree/Library/Developer/Xcode/DerivedData/examp-etciozbcfzozwlckbgilctoxatkh/Build/Products/Debug/examp

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

      1. Seems like it’s not searching for the library at the appropriate path. ld: library not found for -lopencv_core.2.4.9

      2. In a similar fashion to adding /usr/local/include to your header search path, you need to add /usr/local/lib to your library search path.

  8. Hey there,

    Having some issues at the end. I’m trying to compile and I keep getting linker errors. It happens to whichever dylib is set first in the “link from library” phase. If I move it around, it gets stuck on that one. Is there something I’m missing? Tried a few times with new projects, following the steps again.

    Thanks for the great tutorial

    1. Fixed this!
      I had to add “/usr/local/lib” to Library search paths.
      I guess it wasn’t searching for the libraries anywhere useful?

  9. I’m 1 week stuck ๐Ÿ™
    I followed all your steps, but
    “ld: warning: ignoring file /Users/radwayahya/OpenCV-2.4.2/mybuild/lib/libopencv_highgui.2.4.2.dylib, file was built for unsupported file format which is not the architecture being linked (armv7)”

    any idea ?! thank you in advance. and a lot of thanks for your easy , pure guide

      1. I dont remember to be honest, but don’t worry too much about the warnings as long as you don’t get an error. Unfortunately, I don’t know what’s causing the architecture error. ๐Ÿ™ Hopefully, someone here can help you out or give you some inspiration. Did you try reading all the comments?

      2. Some users have had luck when they started from scratch over again. Try that. Are you on Mac Snow Leopard?

          1. Firstly A lot of thanks, Tilo ๐Ÿ™‚
            Secondly .. I didn’t find a luck to get opencv2.4.2 to work with this way.
            So I’m sharing the alternate way I followed :-
            1- Download opencv2.framework from (it’s a prebuilt framework -ready to use directly- ) [ ]
            2- Add it to xcode project as adding any library. if you don’t know about that, don’t worry ๐Ÿ™‚ read the content under the title “Adding the OpenCV Framework” from [ ]
            3- Add headers >> Follow the steps under the title “Include the OpenCV headers” from [ ]
            4 – Write your test code and Run.

            I’m using Mac OS X Lion 10.7.4, XCode 4.3.2 and wanted to run opencv on iPhone with IOS 5.1
            — Enjoy ๐Ÿ™‚

  10. Kindly what’s the Python bindings for OpenCV means?
    Is python needed for installation !!!!!!! or you will use it as a programming language for opencv across their python interface ?

    1. The Python bindings are just an easier API over the C++ API. It’s not necessary for installation. In fact, I was never able to get Python OpenCV working.

  11. The installation was an easy walk with your instructions. But, I am getting an error while building the code and it is “Lexical or Preprocessor Issue” “cvaux.h” file not found.

    I have added the /usr/local/include to both Header search paths and user header search paths (individually and both together).

    The file at which it is pointing the error is “cvaux.hpp” (of version 2.4 of OpenCV).

    Any idea on why xcode is not looking into the appropriate header file paths?. I am running this on Xcode 4.4 and on a Mac OSX Lion.

  12. Thanks so much. I’ve been reading Learning OpenCV and wanting to start writing code. I’m a iPhone/Mac OS X GUI programmer so the Terminal and low level stuff is new to me. Like you, I found the task of getting all the pieces in the right place in the right order pretty daunting. I am running Mountain Lion, Xcode 4.4.1, and downloaded Open CV 2.4.2. All is working well. I had a couple of problems that I overcame and am posting them in case others have the same issues.
    1.) I had spaces in directory names (noob mistake). Replaced them with underscores.
    2.) I made my project a C project, needed to be C++
    3.) In Xcode build settings, I had to add /usr/local/lib to library search paths
    4.) Took me a minute to figure out where the built app was so I could place my .jpg to be converted. Easiest way to get there is right click on the file under the “Products” folder in Xcode and select “Show in Finder” put your .jpg here and obviously the .png that is created will show up here.

    Hope this info might help someone. Thanks again for the tutorial, you save me a lot of time. Now it’s time to play…

  13. the installing process went fine, but when trying to build the test code i get an error; ‘cvaux.h’ file not found.
    i’m running lion, did the header and search path thing and am now puzzled… any ideas?

  14. Hi Tilo,

    So great your guide is! Thank you for your information.

    I encountered only one error like: Lexical or Preprocessor Issue, ‘cvaux.h’ file not fond.

    It is so weird since the other two header files are included correctly. And all the step in your guide were run without any error. When setting the header search paths, should I change the value at “debug” or “release”? And when I try to run the cpp file, should I just click on the button “Run”? This is my first time of using the Xcode, so the questions sound “naive”…..

    Thank you for you information.

    1. btw, I can exactly see the file “cvaux.h” and “cvaux.hpp” are existing in the folder “/usr/local/include/opencv”.

      I don’t know why it is still not found.

    2. Sorry Jianxu. It’s been a while, so I forget a lot of the implementation details. Your best bet would be to check the comment thread here, as people often post their solutions. ๐Ÿ™‚

      1. Try changing the path you added (/usr/local/include) from non-recursive to recursive. The snippet needs header from both opencv and opencv2

  15. Hi Tilo,

    I am running OSX10.7.4 and XCode 4.4.1. I’m getting started in OpenCV and I followed your steps above. When I compile my code, I get the error below.

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

    Not sure how to correct this one. Can you help me troubleshoot?


  16. First I want to thank you about this guide, i am new to mac so i faced a lot of issues but finally i got everything working, i want to post to help anyone facing the same.
    I have OS X 10.7.5 and opencv 2.4.2

    1. I faced problems with the command –> cmake -G “Unix Makefiles” .. downloads -> components, and click install on โ€œCommand Line Toolsโ€ and itโ€™ll do everything for you.

    2. After adding the libraries i got that error, –> linker command failed with exit code 1 (use -v to see invocation) <–, to solve it i include (/usr/local/lib) in "Library Search Paths" just like including (/usr/local/include) in "Header Search Paths".

    1. I don’t know why some words were removed from step 1 so i will write it again,
      1. I faced problems with the command โ€“> cmake -G โ€œUnix Makefilesโ€ .. downloads -> components, and click install on โ€œCommand Line Toolsโ€ and itโ€™ll do everything for you.

  17. Hi, I am unable to change “header search path”. I am using Xcode 4 on Snow leopard. I followed all your instructions. But when I go to header search path, all I get are two sub blocks i.e ‘Debug’ and ‘release’. I do not know how to proceed. Please help. Thanks..

  18. Hi Tilo,
    Everything runs correctly up to the point where I run the code. The code builds successfully but I can’t seem to read the image. My code always ends up in the ‘if(!pInpImg)’ loop.

    I placed the image with my code and still I get the same error.

    How do I go about troubleshooting this?

  19. After a week of trying to install OpenCV I finally encounter this forum and finally my test compiles without errors!!! However I’m new to using a mac structure so the code is not finding “my_image.jpg”. How do I reference to some place in the storage…. what in pc would be something like “C:\my_image.jpg”?

    1. Easy way to do it – right click on your image and click “Get Info”. It will show the direct path to the image folder. Use that.

  20. Very good tutorial! Wish I read this first.
    It took a long time to install it from tar.bz2 and often failed. After that i installed OpenCV with Macports. Worked fine, but “dylib” directory is /opt/local/lib and header files were placed in /opt/local/include/opencv and /opt/local/include/opencv2.
    Creation and setup of the XCode project worked as described. Thank you for that!

  21. Thanks a lot dude, it took a while but on my Mac with 10.6.8 with Xcode 4.2 it worked all in the end. Appreciate it!!

  22. Hi, it is excellent tutorial
    I got these error, what I suspect about is the dylib files because when I search by typing in /usr/local/lib
    I didn’t found and dylib file so I went manually to opt\local\lib and add every dylib file
    these are the errors:

    /usr/local/include/opencv2/video/background_segm.hpp:48:1: Unknown type name ‘namespace’
    /usr/local/include/opencv2/video/background_segm.hpp:48:13: Expected ‘;’ after top level declarator
    /usr/local/include/opencv2/objdetect/objdetect.hpp:81:20: ARC forbids Objective-C objects in structs or unions
    /usr/local/include/opencv2/objdetect/objdetect.hpp:81:5: Unknown type name ‘CvHaarFeature’; did you mean ‘CIFaceFeature’?
    /usr/local/include/opencv/cvaux.hpp:49:10: ‘cvaux.h’ file not found

    1. Thanks for the kind words! Unfortunately, I’m no longer using OpenCV so I’ve forgot a bunch of these things. Try looking through these comments – people have left lots of tips!

  23. Hey, Tilo!
    Thanks a lot for your tutorial!
    I changed the header search path, however even after that it says header file not found ๐Ÿ™ Can you help me out please? ๐Ÿ™

    1. Hey Prerna! Thanks. Unfortunately, it’s been a while so I don’t really remember ๐Ÿ™ Try looking through these comments. People often leave tips about things they did that made it work for them, so hopefully you’ll find something.

      Seems straight forward – you just need to alter the path to something so that the program catches it.

  24. Hi,
    so far everything in the tutorial worked out fine, but when I search for “Header Search Paths”, I don’t see where to change the path to /usr/local/include ?

  25. Hi,
    nice tutorial, but I think you missed this step (before the last one):
    Add the path to your library to the “Library Search Paths” (under “Search Paths”). In your case this will be /usr/local/lib

  26. Many thanks for an excellent step by step guide. Also thanks to those who took the trouble to post their solutions to problems.

    I thought I would add a comment that this works fine with Mountain Lion 10.8.2 and Xcode 4.5.2. The tip about installing the command line tools from the XCode Preferences->Downloads is a real good one. It’s a single click option.

    I had no issues with the build of the OpenCV components. I used the 2.4.3 version.

    When it came to building the test application I had a couple of the issues mentioned in the comments. I though I would let people know my solutions.

    First the missing header file “cvaux.h”. The solution to this is to make sure that the header search path is listed as “recursive” when you add “/usr/local/include” to the header search path. No need to substitute files or rename things.

    The second problem is the linker error. This depends on how you added the libopencv_xxxx files to your project. If when you added the files you let XCode copy the files to the project directory you don’t get this problem. If you un-checked the “add files to project” option then you will get the error. Its a personal preference if you want to add the libraries to the project but if you chose not to you will need to add the path “/usr/local/lib” to the “Library Search Paths”

    I saw a number of comments about the app not finding the image file. This needs to go in the same folder as the application, right click on the app under products and show in finder. And the important point is that the image file needs to be called my_image.jpg ๐Ÿ™‚ That one took me a couple of goes before I was groaning at my stupidity.

    Once again, this is one of the best How To’s I’ve ever used. Thank you

    1. Thanks so much for posting this! I’m sure it’ll be useful to a LOT of people. I personally really appreciate this.

    2. Awesome, thanks for all of these fixes! They were all just what I needed. And this guide was also great.

  27. i get this error message when a i try to compile the code:

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

  28. Hi –

    Trying to install this – have installed/downloaded all the required apps and compilers. Receiving following error at first command:

    Miless-Macbook-Pro:~ Apple$ sudo port install cmake
    Warning: The Command Line Tools for Xcode don’t appear to be installed; most ports will likely fail to build.
    Warning: See for more information.
    —> Computing dependencies for cmakeError: Unable to execute port: can’t read “build.cmd”: Failed to locate ‘make’ in path: ‘/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin’ or at its MacPorts configuration time location, did you move it?
    Miless-Macbook-Pro:~ Apple$ sudo port install cmake
    Warning: The Command Line Tools for Xcode don’t appear to be installed; most ports will likely fail to build.
    Warning: See for more information.
    —> Computing dependencies for cmakeError: Unable to execute port: can’t read “build.cmd”: Failed to locate ‘make’ in path: ‘/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin’ or at its MacPorts configuration time location, did you move it?
    Miless-Macbook-Pro:~ Apple$

    Can’t go further.

    Please advise!

    Many thanks.

  29. I finally got everything to compile (turns out it was an issue with macports installing to opt rather than usr… I simply copied all of the headers to /usr/local/include and it solved the problem).

    but now I have a problem with the image file. I followed the instructions + the suggestions in the comments. But I keep getting the error:

    dyld: Library not loaded: /opt/local/lib/libopencv_stitching.2.4.dylib
    Referenced from: /Users/leighchristie/Library/Developer/Xcode/DerivedData/TestOpenCV-gdnvvfcjdkengubdgvxotlxpxfyn/Build/Products/Debug/TestOpenCV
    Reason: image not found

    any ideas?

  30. Hi there –

    I sent a reply about a week ago, but I am not sure if you received it. I am desperately looking for help in trying to make a build. I get the following error no matter what I try:

    Apple$ sudo port install cmake
    Warning: The Command Line Tools for Xcode don’t appear to be installed; most ports will likely fail to build.
    Warning: See for more information.
    —> Computing dependencies for cmakeError: Unable to execute port: can’t read “build.cmd”: Failed to locate ‘make’ in path: ‘/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin’ or at its MacPorts configuration time location, did you move it?

    Could you possibly kindly let me know how to resolve this ASAP? Much appreciated!

    Kind regards,


  31. In terminal i’ve installed cmake and build OpenCV. When i’m typing ls /usr/local/lib i’ve got a lot of files .dylib. When I link the .dylib files in my project and text in /usr/local/lib, there are no .dylib. via terminal i see but via “Add Files to ..” i don’t .Tell me plz what’s wrong. Thanks !!!!

  32. Worked great on 10.6.8 Using Xcode 4.2 !

    I don’t have make ports or fink, but I had installed cmake for a other stuff.

    downloaded source

    cmake -G “Unix Makefiles”
    make -j8
    sudo make install

    Who cares if the source tree gets corrupted you can always re-create from tar file.

    Sophia, open terminal
    cd /Library
    ln -s /usr/local local

    Now you can add the files using the standard dialog by navigating to /Library/local

  33. Hello All,

    I thought I would add a little bit of detail to step 1, which tripped me up a bit.

    When you create your xCode project, be sure to set the project “Type” to C++, (using the appropriate dropdown list/selector). Otherwise, the project “Type” is set to C by default. In xCode 4.6, this setting appears on the second screen of project creation.

    When I created the default C project, obviously a main.c file was automatically created. And when I went to compile/build, I received the following error:
    Lexical or Preprocessor Issue ‘list’ file not found

    The issue went away and the compile/build succeeded after I created a new C++ project.

  34. Another point of clarification,

    In addition to properly naming your image file “my_image.jpg”, you must put the image in the same directory where your TARGET APPLICATION resides, not the directory where your source code resides. You can find this directory by right clicking on the appropriate target in your project’s Products folder, and then selecting “Show in Finder”.

    Put the image there.

    Then, do not double click the application in that folder. I tried that and it didn’t work. You must actually “Run” the application from xCode by selecting Product -> Run from the main dropdown menu. After running, you should navigate back to the folder with the target application. You should notice a new file “my_image_copy.png” in there.


  35. Thanks for tutorial but I have found this issue on Xcode 4.5.2
    /usr/local/include/opencv2/video/background_segm.hpp:47:10: ‘list’ file not found

    #include “opencv2/core/core.hpp”
    #include ///
    namespace cv

  36. Thanks for your instructions, I have two questions to ask
    1 : How could I change the install path?What if I want it to install under path

    2 : How could I change the default compiler use to compile the openCV?I would like to use
    clang3.3 rather than the default compiler–gcc4.7.2

    Thanks a lot

  37. hi when i am trying to install the open cv i get following error and while i went to /usr/local/ i couldnt any fine except CUDA which i had installed before why is this problem. i have attached the error message hereclang: error: unsupported option ‘-dumpspecs’
    clang: error: no input files
    CMake Error at (message):
    Error generating

  38. i’m getting an error in calling a function “cv_xadd” during building of the example. Could you please help?

  39. Hello thanks for the great Tutorial!
    I’m getting this error when I’m on make -j8 on terminal.

    [ 18%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./
    clang: error: unsupported option ‘-dumpspecs’
    clang: error: no input files
    CMake Error at (message):
    Error generating

    I saw some similar comments but not the exact problem, so what do you think?

  40. Hi! Thanks for the tutorial.
    Iโ€™m getting this error when Iโ€™m on make -j8 on terminal.

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.2.4.3.dylib] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs….
    [ 49%] Built target pch_Generate_opencv_perf_stitching
    [ 49%] Built target pch_Generate_opencv_test_video
    [ 49%] Built target pch_Generate_opencv_perf_objdetect
    make: *** [all] Error 2

  41. hello Tilo,

    thank you for your post, I followed everything you mentioned but my Xcode tells me that the function cvLoadImage and cvSaveImage are undeclared. I did set the right header search path but I have no idea why Xcode can’t find them.

    I am currently running Mac 10.9 and Xcode 5.0.1

    1. oh well i solved it, i have to add this header in the code:

      #import “OpenCV/highgui.h”

      this is strange, I can remove all the other headers and just leave this highgui.h alone, then the code will just work fine, otherwise, it fails to build.

      Any thoughts on my situation?

  42. Thank you for this tutorial but I just find a error in Xcode using opencv.

    dyld: Library not loaded:
    Referenced from: /Users/mantonoeki/Library/Developer/Xcode/DerivedData/finaltry-gopuwqkwhbmwuzffzxtztcwjwzsm/Build/Products/Debug/finaltry
    Reason: image not found

    Do you know what does it mean?

    1. go to build phases and set the status of to optional. This fixed the problem for me.

  43. Hi,

    thank you for the tutorial. While trying to build the program I got this error: “/usr/local/include/opencv/cvaux.hpp:49:10: ‘cvaux.h’ file not found with include; use “quotes” instead”. I tried the solution in this page to change to cvaux.hpp to cvaux.h and it did work. Is this the right way to do it?

  44. I followed the steps, and install the OpenCV successfully. However, there is only on file (opencv.hpp) int the folder includes, which should contains some other folders. I want to know why

  45. Hey I have downloaded opencv and tried to configure it till the step of this command cmake -G “Unix Makefiles” .. it was fine but later when I typed make -j8

    like this
    11 error generated.
    error generated.
    1 error generated.
    make[2]: *** [3rdparty/libjasper/CMakeFiles/libjasper.dir/jas_cm.c.o] Error 1
    make[2]: *** [3rdparty/zlib/CMakeFiles/zlib.dir/deflate.c.o] Error 1
    make[2]: *** [3rdparty/libjpeg/CMakeFiles/libjpeg.dir/jccoefct.c.o] Error 1
    make[1]: *** [3rdparty/libjpeg/CMakeFiles/libjpeg.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs….
    make[1]: *** [3rdparty/zlib/CMakeFiles/zlib.dir/all] Error 2
    1 error generated.
    make[2]: *** [3rdparty/libjasper/CMakeFiles/libjasper.dir/jas_icc.c.o] Error 1
    make[1]: *** [3rdparty/libjasper/CMakeFiles/libjasper.dir/all] Error 2
    make: *** [all] Error 2

    I am not able to move ahead help me out in this regard.

  46. Hi Tilo

    As I am new to this I had already installed
    MacPorts… but hadn downloaded the .dmg file.
    and I dono how to go about it.
    It wud be great if u cud help me out in this



  47. Hi Tilo, thanks a lot for the installation tutorial. I’ve done the installation but when I tried to run the given code, I didn’t get the result as I expected. It was said
    “failed to load input image
    Program ended with exit code: 255”.
    I already download some jpg picture and rename it to my_image.jpg as well. Do you have any idea how to fix it? Thanks before for your help and attention.

    1. Sorry Markus, I haven’t looked at this code for a while so I don’t think I can help you out much. You should check the comments to see if theres a solution.

  48. Thanks for another fantastic article. Where else could
    anyone get that type of info in such an ideal approach of writing?
    I’ve a presentation subsequent week, and I’m at the search for
    such info.

  49. Everything is working fine but I can’t get rid of this error:
    Command /System/Library/Frameworks/OpenCL.framework/Libraries/openclc failed with exit code 1

  50. I have downloaded openCV-3.0.0-beta version.
    The download completed perfectly.
    My .cpp file is failing to recognize the libraries:

    Please help.

  51. Hi, i want to use openvb on netbeans with yosemite. how i have to do? hope you can help me. thanks

  52. Thanks for the tutorial, really helpful. After completing all the steps, I encountered an build error:
    “base.hpp” header must be compiled as C++
    “core.hpp” header must be compiled as C++

    I found the solution here:
    (don’t include xxx.hpp in xxx.m(objective-c style), include xxx.hpp in xxx.cpp(c++ style))

    Just write down this for whom encounters the same error.

  53. Thank you so much, this was the only place I could find that directly told me how to do all this! Thank you so much! It all works great for OpenCV 3.0 too.

  54. Hi ,

    Very much enjoyed this post, however, I’m getting an odd error. First off, none of my files in /usr/local/lib end in .dylib, they all end in .a. Secondly, I get this error that overflows my error stack: Apple-Mach 0 Linker (id) error

  55. This was very helpfull , i want to install the dlib C++ library into xcode (iOS), if you can provide me some details or steps this will great.

  56. After write cmake -G”Unix Makefiles”.. I got CMake Error: Could not create named generator Unix Makefiles..
    So what could i do?

  57. hey
    I had followed your steps ..
    But I got an error like this..

    Apple Mach-O-Linker(id) Error
    Liker command failed with exit code 1(use -v to see invocation)

Comments are closed.

Up Next:

Some Interview Help

Some Interview Help