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

后端 未结 5 1488
忘掉有多难
忘掉有多难 2020-12-02 11:25

I am currently a real beginner in Objective C, and I am developing an app using the framework OpenCV.

I am following a tutorial, but while builing the project, I got

相关标签:
5条回答
  • 2020-12-02 11:45

    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.

    0 讨论(0)
  • 2020-12-02 11:46

    I had a similar problem, try removing "-lopencv_ts" from "Other Linker Flags"

    0 讨论(0)
  • 2020-12-02 11:53

    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.

    0 讨论(0)
  • 2020-12-02 11:57

    The user can also add the libc++.tbd if libc++.dylib is not available in the "Link Binary With Libraries"

    Thanks Mitesh

    0 讨论(0)
  • 2020-12-02 12:03

    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"
    0 讨论(0)
提交回复
热议问题