Compiling opencv 2.4 on a 64-bit Mac in Xcode

I have an opencv project that I developed under ubuntu 12.04, on a parellels virtual machine on a Mac with x86_64 architecture. There were many problems with switching screens, which, it seems to me, are associated with a virtual machine, where the video modes in linux mode are turned upside down for a couple of seconds, while the cameras are accessed by the opencv application. I decided to move the project to Xcode on the Mac side of the computer to continue developing opencv. However, I am not familiar with xcode, and I am having problems with the fact that the project will be created correctly.

I have xcode installed. I downloaded and unpacked the latest version of opencv on mac and ran: ~ / src / opencv / build / cmake-gui -G Xcode .. according to the instructions from willowgarage and elsewhere. This seems to work fine (however, I am now wondering if there is a lack of architecture here, although this is the 64-bit version of intel in Xcode). Then I install the xcode project with the source files from the linux project and change the include directories to use / opt / local / include / ... rather than / usr / local / include / ... I switched xcode to use the GCC LLVM compiler in the build settings for the project, then set the Apple LLVM dialog for C ++ to the language dialect in GNU ++ 11 (which, apparently, is incompatible with the line above)

I do not use makefile in xcode (what I know - it has its own project file ...)

I also ran into a linker problem that looked like they could be resolved with the addition of this linker flag:

-lopencv_video 

based on a similar publication here: another thread however, in this case, the person used the Makefile in his project.

I tried to add this linker flag in the "Other linker flags" section of the xcode build settings, but still get build errors.
I think I can have two problems: one with the architecture settings when creating opencv libraries with Cmake and one with the linker flag settings in my project.

Currently, the list of build errors is as follows:

  Undefined symbols for architecture x86_64: "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from: _main in main.o "cv::_OutputArray::_OutputArray(cv::Mat&)", referenced from: _main in main.o "cv::Mat::deallocate()", referenced from: cv::Mat::release() in main.o "cv::Mat::copySize(cv::Mat const&)", referenced from: cv::Mat::Mat(cv::Mat const&)in main.o cv::Mat::operator=(cv::Mat const&)in main.o "cv::Mat::Mat(_IplImage const*, bool)", referenced from: _main in main.o "cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from: _main in main.o ---SNIP--- ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status 

Can someone give some recommendations on what to do next?

Thanks Walt

+8
opencv
source share
1 answer

steps to compile and run C ++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1 EDIT: successfully tested with opencv 2.4.5 on mac os x mountain lion 10.8.3 and Xcode 4.5

Availability of necessary tools

Use cmake to compile opencv

  • go to the extracted opencv folder
  • create assembly directory

     mkdir build cd build cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" .. make -j8 sudo make install 
  • from the build folder, go to bin / and run one of the tests

     ./opencv-test-photo 

Create your own c ++ opencv xcode project

  • run xcode and create a new xcode project
  • select command line tool for project type under os x
  • open the project build settings.
  • in the Architecture section, set Architecture to 64-bit intel. also set valid architectures to x86_64
  • in the "Assembly Options" section, set the compiler for the default C / C ++ compiler
  • In Search Paths, set header search paths to / usr / local / include
  • also in the "Search Paths" section, set the library search paths to / usr / local / lib
  • in the Apple compiler LLVM 4.2 - Language Suite C ++ Standard Library for libstd ++ (with OpenCV 2.4.6, Xcode 5, LLVM 5.0 and 10.8.5 instead, set the language dialogs and the standard library to "Default Compiler")

Add compiled opencv libraries to your project

  • go to the "Construction Phases" tab next to the "Settings" tab in which you were:
  • inside Link Binary With libraries, click the + sign and select Add Other
  • press the forward slash / on the keyboard and type / usr / local / lib
  • press enter and select the libraries you want to use in your project.
  • make sure you always choose libopencv_core.2.4.4.dylib
  • press enter and you will see the selected dylib under your project.

write code

  • first organizes the files, right-click the icon of your project and select "New Group"
  • enter a new opencv group or something else
  • drag and drop dylib and drop them into this group.
  • open main.cpp
  • copy the code from any of the test tests that come with opencv and paste it here.
  • make sure that all the necessary dylibs are added, for example, if you copied opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps

    • libopencv_core.2.4.4.dylib
    • libopencv_highgui.2.4.4.dylib
    • libopencv_stitching.2.4.4.dylib

Greetings.

+15
source share

All Articles