1
\$\begingroup\$

I am trying to use the iOS version of ORB_SLAM2 (https://github.com/ygx2011/ORB_SLAM2-IOS) as a plugin to a Unity (Unity 5.5) project. To be able to use this as a plugin, I created a static library (.a file placed in Assets/Plugins/iOS/ directory) from the above iOS app, that can be used to subclass the UnityAppController.

Now, in the Unity player settings, I changed the scripting backend to IL2CPP and the architecture to arm64. The reason I did this is because according to the Unity 5.5 Legacy documentation, IL2CPP is the only scripting backend to support deploying to ARM 64-bit on iOS.

When I build and run the generated Xcode project, I get the following errors with regards to arm64 architecture.

Undefined symbols for architecture arm64:

"cv::String::deallocate()", referenced from: cv::String::~String() in libORBSlamLib.a(ORBSlamLib.o) cv::String::operator=(cv::String const&) in libORBSlamLib.a(ORBSlamLib.o)

"cv::error(int, cv::String const&, char const*, char const*, int)", referenced from: cv::Mat::operator cv::Vec() const in libORBSlamLib.a(ORBSlamLib.o) cv::Mat::Mat(int, int, int, void*, unsigned long) in libORBSlamLib.a(ORBSlamLib.o)

"cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)", referenced from cv::Mat::colRange(int, int) const in libORBSlamLib.a(ORBSlamLib.o) cv::Mat::rowRange(int, int) const in libORBSlamLib.a(ORBSlamLib.o) cv::Mat::col(int) const in libORBSlamLib.a(ORBSlamLib.o)

"ORB_SLAM2::System::TrackMonocular(cv::Mat const&, double const&)", referenced from: -[ORBSlamLib libProcessImage:] in libORBSlamLib.a(ORBSlamLib.o)

"cv::projectPoints(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, double)", referenced from: -[ORBSlamLib libProcessImage:] in libORBSlamLib.a(ORBSlamLib.o)

"cv::circle(cv::InputOutputArray const&, cv::Point, int, cv::Scalar_ const&, int, int, int)", referenced from: -[ORBSlamLib libProcessImage:] in libORBSlamLib.a(ORBSlamLib.o)

"_inverse", referenced from: _LLIMUPosMgr_inverse_m3594686272 in Bulk_Assembly-CSharp_3.o _LLIMUPosMgr_KFUpdate_m728291423 in Bulk_Assembly-CSharp_3.o

"cv::noArray()", referenced from: -[ORBSlamLib libProcessImage:] in libORBSlamLib.a(ORBSlamLib.o)

"_multiply", referenced from: _LLIMUPosMgr_multiply_m1606521480 in Bulk_Assembly-CSharp_3.o _LLIMUPosMgr_KFPredict_m2919581928 in Bulk_Assembly-CSharp_3.o _LLIMUPosMgr_KFUpdate_m728291423 in Bulk_Assembly-CSharp_3.o

"_subtract", referenced from: _LLIMUPosMgr_subtract_m949145514 in Bulk_Assembly-CSharp_3.o _LLIMUPosMgr_KFUpdate_m728291423 in Bulk_Assembly-CSharp_3.o

"cv::Rodrigues(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&)", referenced from: -[ORBSlamLib libProcessImage:] in libORBSlamLib.a(ORBSlamLib.o)

"cv::fastFree(void*)", referenced from: _mGetPose in SlamAppController.o cv::Mat::~Mat() in libORBSlamLib.a(ORBSlamLib.o)

"_add", referenced from: _LLIMUPosMgr_add_m3985982311 in Bulk_Assembly-CSharp_3.o

I noticed that most of these errors occurs in opencv functions, so I cross checked if the opencv2.framework included in the project is built with arm64 support. But from the opencv forums it's mentioned the latest version of opencv does support arm64 (I cloned the opencv GitHub repository and followed these instructions on the opencv documentation to generate the framework). I've already played around with the commonly recommended solutions from posts like https://stackoverflow.com/questions/22375531/how-to-update-our-static-library-architecture-for-suporting-arm64-build , http://answers.unity3d.com/questions/912000/apple-mach-o-linker-error-when-building.html, https://stackoverflow.com/questions/6429494/undefined-symbols-for-architecture-armv7, etc. From the forums I've come across, the following build settings have worked for others.

Architectures - Standard ARCHS.

Build Active Architecture Only - Debug set to YES; Release set to NO.

Supported Platforms - iphoneos

Valid Architectures - arm64 armv7 armv7s

Framework Search Paths - $(PROJECT_DIR) where the opencv2.framework is located.

C++ Language Dialect - GNU++11 (couldn't set this to C++11 since GNU++11 is required by another framework called GLKit - could this be the problem? Is there a workaround for this?)

C++ Standard Library - libc++ LLVM C++ Standard Library with C++11 support.

I'm a beginner in both Unity & iOS and any help would be really appreciated. I use Unity 5.5.2f1, Xcode 9 beta 3 and an iPhone 7 Plus with iOS 11 beta 4 for my project.

P.S. The ORB_SLAM2-IOS works fine if compiled directly as an iOS app. The problem occurs only when I try to use it as a static library.

Thanks!

\$\endgroup\$
  • \$\begingroup\$ Are those all the errors? During my time with xcode often some libs were missing during compile time or something like bitcode enabled caused the error. Make sure that every lib you add is up to date. \$\endgroup\$ – Sidar Jul 27 '17 at 6:05
  • \$\begingroup\$ Yes these are all the errors. I did have those bitcode related errors before but when I compiled the library and the app with bitcode enabled, those errors went away. \$\endgroup\$ – Vivek Arvind Jul 27 '17 at 14:26
  • \$\begingroup\$ All I can think of is that maybe one of your plugins/libs is outdated but I haven't worked with xcode in such a while that I don't remember. Sorry \$\endgroup\$ – Sidar Jul 27 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.