Last active
May 21, 2016 14:12
-
-
Save balazspete/6982565 to your computer and use it in GitHub Desktop.
How to: Set up OpenCV on MacOS X and XCode 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###Download XCode from the App Store | |
Get it from [here](https://itunes.apple.com/en/app/xcode/id497799835?mt=12) | |
###Get cmake | |
Use/get a package manager, such as [homebrew](http://brew.sh/). | |
Open a terminal window and type the following | |
``` | |
brew install cmake | |
``` | |
This will get the required packages for *cmake*. | |
###Get and install OpenCV | |
* Download the latest [OpenCV for Linux/Mac](http://opencv.org/downloads.html) | |
* Navigate to location of downloaded file and untar it with the following command | |
``` | |
tar xvzf opencv-2.4.6.1.tar.gz | |
``` | |
* Navigate to extracted folder `cd path/to/folder` | |
* Create a build directory and build opencv with the following commands | |
``` | |
mkdir build | |
cd build | |
cmake -G "Unix Makefiles"... | |
``` | |
* Make and install | |
``` | |
make -j8 | |
sudo make install | |
``` | |
###Set up an OpenCV project in XCode | |
* Start XCode | |
* Create new "Command Line Tool" project with type `C++` [screenshot](https://f.cloud.github.com/assets/285590/1329495/379c7872-3518-11e3-8e11-3a83b45c01f8.png) | |
* **Add OpenCV to your project** | |
* Right click your project on the sidebar, select "Add files to..." [screenshot](https://f.cloud.github.com/assets/285590/1329506/6ec69918-3518-11e3-9a17-c09404fe4d28.png) | |
* When the file chooser dialog opens up, press `cmd` + `shift` + `G` and enter "/usr/local/lib" [screenshot](https://f.cloud.github.com/assets/285590/1329515/974f0ff0-3518-11e3-9568-ce6530c7c6c0.png) | |
* Select the required OpenCV files (named in the format `libopencv_*.dylib`), or select all. Press `Add` or `Return` [screenshot](https://f.cloud.github.com/assets/285590/1329526/af92fb62-3518-11e3-9b41-b012f00b09b2.png) | |
* You will see that all selected files are now in the sidebar. You can youp them together by creating a new _Group_ and dragging the files in there. [screenshot](https://f.cloud.github.com/assets/285590/1329527/c25dac2e-3518-11e3-8ab3-5b3d3412260a.png) | |
* **Configure your project** | |
* Click on the project (in the side bar), and you should see the Project settings come up in the middle of the editor | |
* Click the `All` view (top left corner) | |
* In the search bar type "**Header Search Paths**", double click the value, remove the existing entries and add | |
`/usr/local/lib` and `/usr/local/include` [screenshot](https://f.cloud.github.com/assets/285590/1329534/00b1b416-3519-11e3-86f8-fa214990f7f2.png) | |
* Now search for "**Library Search Paths**" and replace the values with `/usr/local/lib` | |
* Search for "**C++ Standard Library**" and select "*libstdc++ (GNU C++ Standard Library)*" [screenshot](https://f.cloud.github.com/assets/285590/1329538/0f478456-3519-11e3-9643-1b6500bb7080.png) | |
* **Try the configuration** | |
* Run one of the sample OpenCV projects | |
Thank you. This really helped me set up OpenCV in Xcode. Thanks a lot again.
@dantesc, I had similar errors which were solved by switching the "C++ Standard Library" setting in my Xcode project's "Build Settings" fromlibstdc++
to libc++
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I follow this steps but i have error when compiling:
Ld /Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Products/Debug/opencv_test normal x86_64
cd /Users/diegopuentes/Documents/opencv_test
setenv MACOSX_DEPLOYMENT_TARGET 10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Products/Debug -L/usr/local/lib -L/usr/local/lib/python2.7/site-packages -F/Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Products/Debug -filelist /Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Intermediates/opencv_test.build/Debug/opencv_test.build/Objects-normal/x86_64/opencv_test.LinkFileList -mmacosx-version-min=10.9 -stdlib=libstdc++ -lopencv_video.2.4.7 -lopencv_flann.2.4.7 -lopencv_stitching.2.4.7 -lopencv_core.2.4.7 -lopencv_photo.2.4.7 -lopencv_legacy.2.4.7 -lopencv_objdetect.2.4.7 -lopencv_ml.2.4.7 -lopencv_superres.2.4.7 -lopencv_ocl.2.4.7 -lopencv_videostab.2.4.7 -lopencv_contrib.2.4.7 -lopencv_imgproc.2.4.7 -lopencv_highgui.2.4.7 -lopencv_nonfree.2.4.7 -lopencv_features2d.2.4.7 -lopencv_calib3d.2.4.7 -lopencv_gpu.2.4.7 -Xlinker -dependency_info -Xlinker /Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Intermediates/opencv_test.build/Debug/opencv_test.build/Objects-normal/x86_64/opencv_test_dependency_info.dat -o /Users/diegopuentes/Library/Developer/Xcode/DerivedData/opencv_test-dsxczmtldmtrgiddqoomxytfgijt/Build/Products/Debug/opencv_test
Undefined symbols for architecture x86_64:
"cv::getTextSize(std::string const&, int, double, int, int*)", referenced from:
_main in main.o
"cv::imshow(std::string const&, cv::InputArray const&)", referenced from:
main in main.o
"cv::putText(cv::Mat&, std::string const&, cv::Point, int, double, cv::Scalar, int, int, bool)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker command failed with exit code 1 (use -v to see invocation)