OpenCV [Mach-O Linker (Id) Error]

Hi all,

I’ve been struggling line by line to get openCV working in my plugin. I’ve checked every possible cause, which helped reduce the errors from 60+ to 21 to 4, and as an ObjC/C++ newbie, I feel I’m missing something obvious.

Any help would be greatly appreciated.

Undefined symbols for architecture arm64: "cv::drawMatches(cv::\_InputArray const&, std::vector\<cv::KeyPoint, std::allocator\<cv::KeyPoint\> \> const&, cv::\_InputArray const&, std::vector\<cv::KeyPoint, std::allocator\<cv::KeyPoint\> \> const&, std::vector\<cv::DMatch, std::allocator\<cv::DMatch\> \> const&, cv::\_InputOutputArray const&, cv::Scalar\_\<double\> const&, cv::Scalar\_\<double\> const&, std::vector\<char, std::allocator\<char\> \> const&, int)", referenced from: PluginLibrary::createGif(lua\_State\*) in libplugin\_library.a(PluginLibrary.o) "cv::Feature2D::compute(cv::\_InputArray const&, std::vector\<cv::KeyPoint, std::allocator\<cv::KeyPoint\> \>&, cv::\_OutputArray const&)", referenced from: PluginLibrary::createGif(lua\_State\*) in libplugin\_library.a(PluginLibrary.o) "cv::DescriptorMatcher::match(cv::\_InputArray const&, cv::\_InputArray const&, std::vector\<cv::DMatch, std::allocator\<cv::DMatch\> \>&, cv::\_InputArray const&) const", referenced from: PluginLibrary::createGif(lua\_State\*) in libplugin\_library.a(PluginLibrary.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thank you!

Make sure that you’re lining to library in Xcode. To do that select project, your App or Plugin target, whatever your goal is, then click on Build Phases. Expand phase “Link Binary With Libraries”. Make sure you have open cv there, if not, use “+” to add.

Here’s instructions with screenshot: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html

Your error is a “link error” it means that your code is compiled, but can not be put together, because bodies(symbols) for some of the used functions can not be found.

It says “Undefined symbols for architecture arm64: cv::drawMatches…” which means it can not find body for function from OpenCV library. It also looking for arm64 symbol, which mean you building for a Xcode Simulator. Make sure you link library. If it doesn’t help, it is possible that library doesn’t have Simulator symbols. Try building it for device then. It is hard to explain all linking process in forum answer. But this should be enough.

Hi vlads,

Thank you for your answer.

I think it’s important to note this code when tried in main.mm within the main project directory works, it just doesn’t work in the plugin.

But still, I think I’m a step closer. I disregarded putting the framework in the static library because it didn’t change the errors, but now I’m thinking it didn’t work because I didn’t include the libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd in the plugin. Problem is, I get this error when trying to compile:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.tbd is not an object file (not allowed in a library) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.6.0.9.tbd is not an object file (not allowed in a library) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.6.tbd is not an object file (not allowed in a library)

Is there a way to link the plugin to a framework within the project directory?

I don’t think I understand what is going on in your project. You can link to Frameworks same way as I shown in previous post. It works both for libraries and for frameworks.

Also, I’m not sure if you should manually link to libstdc++.

Yes, I can link the library.

OpenCV relies on  libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd being linked.

When I link the library/framework to the plugin, (and delete the reference in the main project), I get the original 26 errors I do when I don’t have libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd linked to the project.

When I try to link any of the .tbd files I get the error above.

So it works when:

  • code is in main.mm

  • framework is in project directory

-  libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd are included

Doesn’t work when:

  • code is in pluginLibrary.mm (or in general terms, within a static library)

Thank you,

Aidan

I’m sorry - I can’t really help with this information. Error you shown before indicates that OpenCV is not linked with your project. Putting it in same directory doesn’t really do anything. I don’t understand if you linked framework or not. Well… Actually error says that you didn’t.

Make sure that you’re lining to library in Xcode. To do that select project, your App or Plugin target, whatever your goal is, then click on Build Phases. Expand phase “Link Binary With Libraries”. Make sure you have open cv there, if not, use “+” to add.

Here’s instructions with screenshot: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html

Your error is a “link error” it means that your code is compiled, but can not be put together, because bodies(symbols) for some of the used functions can not be found.

It says “Undefined symbols for architecture arm64: cv::drawMatches…” which means it can not find body for function from OpenCV library. It also looking for arm64 symbol, which mean you building for a Xcode Simulator. Make sure you link library. If it doesn’t help, it is possible that library doesn’t have Simulator symbols. Try building it for device then. It is hard to explain all linking process in forum answer. But this should be enough.

Hi vlads,

Thank you for your answer.

I think it’s important to note this code when tried in main.mm within the main project directory works, it just doesn’t work in the plugin.

But still, I think I’m a step closer. I disregarded putting the framework in the static library because it didn’t change the errors, but now I’m thinking it didn’t work because I didn’t include the libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd in the plugin. Problem is, I get this error when trying to compile:

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.tbd is not an object file (not allowed in a library) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.6.0.9.tbd is not an object file (not allowed in a library) error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libstdc++.6.tbd is not an object file (not allowed in a library)

Is there a way to link the plugin to a framework within the project directory?

I don’t think I understand what is going on in your project. You can link to Frameworks same way as I shown in previous post. It works both for libraries and for frameworks.

Also, I’m not sure if you should manually link to libstdc++.

Yes, I can link the library.

OpenCV relies on  libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd being linked.

When I link the library/framework to the plugin, (and delete the reference in the main project), I get the original 26 errors I do when I don’t have libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd linked to the project.

When I try to link any of the .tbd files I get the error above.

So it works when:

  • code is in main.mm

  • framework is in project directory

-  libstdc++.tbd, libstdc++.6.tbd, libstdc++.6.0.9.tbd are included

Doesn’t work when:

  • code is in pluginLibrary.mm (or in general terms, within a static library)

Thank you,

Aidan

I’m sorry - I can’t really help with this information. Error you shown before indicates that OpenCV is not linked with your project. Putting it in same directory doesn’t really do anything. I don’t understand if you linked framework or not. Well… Actually error says that you didn’t.