Apple Mach-O linker and multiple "undefined symbols" error using OpenCV Apple Mach-O linker and multiple "undefined symbols" error using OpenCV xcode xcode

Apple Mach-O linker and multiple "undefined symbols" error using OpenCV


Building on Cthutu's answer, to add libc++.dylib to your project:

  1. Select your project (the blue file) in your project navigator(Command 1 if it's hidden)
  2. Select your target
  3. Go to Build Phases
  4. Expand "Link Binary With Libraries"
  5. Click the "+"
  6. Type libc++.dylib in the search bar.
  7. Select the libc++.dylib file and press "Add"


You're missing the standard C++ library. You need to link with it to get all the implementations for the STL classes you're getting errors for.

Add the libc++.dylib to your project.


This actually seems to hide the actual problem: the fact that your LLVM compiler may not choose a proper standard C++ library for compiling by default. You should go to

Project (or your Target) -> Build Settings -> Apple LLVM 6.0 - Language - C++ -> C++ Standard Library

and make sure that you pick libc++ as your choice, not just Compiler Default, since modern OpenCV library is linked against libc++. This will solve your problem without having to add the extra libc++.dylib. Including libc++.dylib framework as a workaround will not always work out if your Compiler Default actually does not choose libc++ library!

To check what "Compiler Default" is, you can do something like this. Mine somehow chooses c++98 as a default.