Cmake: link to iOS library - ios

I've a CMake toolchain that should generate static library to deploy in a suitable client app for a selected platform. Available platform is for now only the iOS, however after running CMake and generate the project (both projects: static library and client are build correctly), Xcode fails to build during the linking process. Strange fact, it's not linking also against basic libraries like “std”.
Here the linking issue:
Undefined symbols for architecture armv7:
"typeinfo for std::codecvt<wchar_t, char, __mbstate_t>", referenced from:
typeinfo for boost::filesystem::detail::utf8_codecvt_facet in boost(utf8_codecvt_facet.o)
"std::codecvt<wchar_t, char, __mbstate_t>::~codecvt()", referenced from:
boost::filesystem::detail::utf8_codecvt_facet::~utf8_codecvt_facet() in boost(utf8_codecvt_facet.o)
boost::filesystem::detail::utf8_codecvt_facet::~utf8_codecvt_facet() in boost(utf8_codecvt_facet.o)
"VTT for std::istream", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in boost(instances.o)
"std::numpunct<char>::id", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in boost(instances.o)
I have created the cmake project as in this sample
somebody has a clue?

Thanks to you all,
I solved by just adding the flag "-stdlib=libc++"(as ComicSansMS suggested, thanks) and command include_directories(${Boost_DIR}) to CMakeLists.txt
thanks
Roberto

Related

Undefined symbols for architecture arm64: "_OBJC_CLASS_$_FIRMessaging"

Hello I am trying to build a firebase unity project in Xcode, after running pod install
and start building the project I get this error :
Undefined symbols for architecture arm64:
"OBJC_CLASS$_FIRMessaging", referenced from:
objc-class-ref in libFirebaseCppMessaging.a(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"firebase::ReferenceCountedFutureImpl::CompleteHandle(unsigned long)", referenced from:
void firebase::ReferenceCountedFutureImpl::CompleteInternal<void, void firebase::ReferenceCountedFutureImpl::CompleteInternal(unsigned long, int, char const*)::'lambda'(void*)>(unsigned long, int, char const*, void firebase::ReferenceCountedFutureImpl::CompleteInternal(unsigned long, int, char const*)::'lambda'(void*) const&) in libFirebaseCppMessaging.a(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"firebase::ReferenceCountedFutureImpl::ReleaseMutexAndRunCallback(unsigned long)", referenced from:
void firebase::ReferenceCountedFutureImpl::CompleteInternal<void, void firebase::ReferenceCountedFutureImpl::CompleteInternal(unsigned long, int, char const*)::'lambda'(void*)>(unsigned long, int, char const*, void firebase::ReferenceCountedFutureImpl::CompleteInternal(unsigned long, int, char const*)::'lambda'(void*) const&) in libFirebaseCppMessaging.a(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"firebase::util::ClassMethodImplementationCache::ReplaceOrAddMethod(objc_class*, objc_selector*, objc_object* ()(objc_object, objc_selector*, ...), objc_class*, bool)", referenced from:
_FirebaseMessagingHookAppDelegate in libFirebaseCppMessaging.a(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
any help?
One thing that you can do is make sure you've added your pod file correctly. Check the syntax is correct and if it's not working at all do a pod deinit, clean your build folder, then reinstall the pod again and run your project.
Making sure there is a link between your target and the file also could be worth looking at. Go to your project manager, select your target, and the link binary with libraries and add your pod file that way.
Xcode unittest build failed with error "Undefined symbols for architecture x86_64"
this helped also when looking around how to solve this. Best of luck.

Xamarin.iOS native linking error MTOUCH MT5210 undefined symbol std::string

My Xamarion.iOS binding project has the links to all the required native video SDK libraries and native OS frameworks. I have set the required frameworks using Frameworks attribute. Other settings include SmartLink=true, ForceLoad=true, IsCxx=true, LinkerFlags="-lc++". It can be built into a C# DLL. In iOS project, the DLL is referenced and used. However there are native linking errors.
MTOUCH: Error MT5210: Native linking failed, undefined symbol: std::string::_Rep::_M_destroy(std::allocator<char> const&). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
The details in build log:
> Undefined symbols for architecture arm64:
> "std::string::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
> HPR_UTF82A(char const*) in libHCCore.a(HPR_Utils.o)
> HPR_A2UTF8(char const*) in libHCCore.a(HPR_Utils.o)
> "std::string::_Rep::_S_empty_rep_storage", referenced from:
> HPR_UTF82A(char const*) in libHCCore.a(HPR_Utils.o)
> HPR_A2UTF8(char const*) in libHCCore.a(HPR_Utils.o)
> "std::string::assign(char const*, unsigned long)", referenced from:
> HPR_UTF82A(char const*) in libHCCore.a(HPR_Utils.o)
> HPR_A2UTF8(char const*) in libHCCore.a(HPR_Utils.o)
> "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char>
> const&)", referenced from:
> HPR_A2UTF8(char const*) in libHCCore.a(HPR_Utils.o)
> "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced
> from:
> HPR_A2UTF8(char const*) in libHCCore.a(HPR_Utils.o)
> ld: symbol(s) not found for architecture arm64
> clang : error : linker command failed with exit code 1 (use -v to see invocation)
The wrap errors:
MTOUCH: Warning MT5215: References to 'System' might require additional -framework=XXX or -lXXX instructions to the native linker (MT5215)
Error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -ObjC (MT5201)
MTOUCH: Error MT5202: Native linking failed. Please review the build log. (MT5202)
clang: Error: linker command failed with exit code 1 (use -v to see invocation)
Please shed light. Thanks.
No such native linking error in Xcode. The build settings:
Managed linking and native linking may remove code. Link All may remove more code. So need to solve the problem instead of making the issues disappear using Link All. When using Link All, need to use Preserve attribute to preserve code.
I added all native references, set the linking options correctly. Also I set the linker flags to include all the required OS platform frameworks correctly. After adding reference to a native dynamic framework, the error disappeared. Then instead of getting undefined symbols, I got duplicate symbols. I had to remove a reference to a native library.
Although the iOS project is linked and built after referencing dynamic frameworks, there is a runtime issue. Our SDK provider confirmed that we must not use their dynamic frameworks. The dynamic frameworks are provided for other customers for a different target SimpleDemo_Dy in Xcode. They are older versions SDK. We should just use the static libraries.
I have re-examined the Xcode build log. No dynamic frameworks are used for target SimpleDemo in Xcode. The question is why Xcode project builds without using any dynamic frameworks, but Visual Studio for Mac build fails with a native linking error?
I’ve created a sample iOS app which only uses static libraries. It builds and runs OK. I've shared the sample iOS app with you. The link is https://drive.google.com/file/d/10QXkaZE7lURN6IF96NIrTGY2lmn88ctF/view?usp=sharing.
I haven’t been able to achieve the same in our product app with identical binding project settings. I even tried to swap the binding project from the sample app. It didn't help. Also I compared the iOS project settings from project options UI and WinMerge. I still couldn't find what's wrong. I have tried clean and rebuild many times. I have tried to check out to a fresh workspace. It still has undefined symbol error.
I think the issue is one of the native libraries libHCCore.a is compiled with libstdc++ which caused the error undefined symbol std::string while the rest are libc++.
Adding Linker Flags -lstdc++ to the native reference didn't help. How to used additional Mtouch arguments in iOS project or additional btouch arguments in binding project to resolve the issue?
See https://github.com/xamarin/xamarin-macios/issues/8669.
We understand that the issue with our iOS app is caused by the mix of libstdc++ and libc++ libraries of our vendor's SDK. Their libHCCore.a was compiled with libstdc++ while all the rest were compiled with libc++. I have tried additional linking options in Visual Studio for Mac, but failed with “libstdc++ is deprecated” and “Library –lstdc++ is not found”. Here is Microsoft Sebastien Pouliot's advice:
I think the issue is one of the native libraries libHCCore.a is compiled with libstdc++ which caused the error undefined symbol std::string while the rest are libc++.
You can't mix both.
Building with libstdc++ was deprecated with Xcode 8 and is not supported in Xcode 10 when targeting iOS. C++ projects must now migrate to libc++ and are recommended to set a deployment target of macOS 10.9 or later, or iOS 7 or later.
...
Project dependencies such as static archives that were built against libstdc++ will also need to be rebuilt against libc++.
https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes?language=objc
You'll need to talk with your vendor to get an updated that is built against libc++
Please rebuild libHCCore.a with libc++.
This issue has been resolved by rebuilding libHCCore.a with libc++ through our vendor.

iOS. Can add RN .a libs instead of installing RN environment?

I create AwesomeProject with RN command.
open it with xcode and build success by simulator.
I find RN .a libs under folder 'Debug-iphonesimulator'.
create a new xcode project and add step 3 .a libs.
build success.
after copy RCTRootView alloc initWithBundleURL codes in AppDelegate, xcode build failed (simulator selected) with 154 common errors :
Undefined symbols for architecture x86_64:
"std::__1::system_error::system_error(int, std::__1::error_category
const&, char const*)", referenced from:
folly::throwSystemErrorExplicit(int, char const*) in libReact.a(JSBigString.o) "std::__1::basic_streambuf >::setbuf(char*, long)", referenced from:
vtable for google::base_logging::LogStreamBuf in libReact.a(logging.o)
vtable for std::__1::basic_stringbuf, std::__1::allocator > in
libReact.a(logging.o)
vtable for std::__1::basic_stringbuf, std::__1::allocator > in
libReact.a(JSCHelpers.o)
I wonder if this way works? Is it necessary to install RN environment?

Xcode: Undefined symbols for architecture i386: DebugStringToFile when building Unity Project for iOS Simulator

I'm struggling with a Linker Error for an iOS project that was created with Unity 4.2.2.
Since the last update of Unity, Xcode can't compile the project anymore, giving me the following error message:
Undefined symbols for architecture i386: "DebugStringToFile(char
const*, int, char const*, int, int, int, int, int)", referenced from:
prcore::Surface::ClearImage(prcore::color32 const&, prcore::Surface::ClearMode) in libiPhone-lib.a(blitter_integer.o)
prcore::Surface::BlitImage(prcore::Surface const&, prcore::Surface::BlitMode) in libiPhone-lib.a(blitter_integer.o) ld:
symbol(s) not found for architecture i386 clang: error: linker command
failed with exit code 1 (use -v to see invocation)
Screenshot:
Choosing the Device SDK and running it on the device works totally fine. But building for the iOS Simulator fails, no matter which settings I try to set in the project settings...
Unfortunately, this a bug in Unity 4.2.2, but will hopefully be fixed soon.
For the meanwhile, this simple workaround will do the job:
open the class main.mm in Xcode
satisfy the Linker by adding a definition for the missing function DebugStringToFile:
void DebugStringToFile(char const*, int, char const*, int, int, int, int, int) { }
Finally, hit build and you're good to go!
Update: Fixed in Unity 4.3:
iOS: Fixed iOS7 simulator support.
iOS: Fixed Xcode 5 build & run for simulator target

compilation error when using boost framework and opencv in ios project

I need to use boost framework in my iOS project. My first mission was getting boost to work for Ios. I tried using this script
http://goodliffe.blogspot.co.uk/2010/09/building-boost-framework-for-ios-iphone.html
but wasn't able to build due to lipo errors (?) and couldn't figure out how to solve it. I looked for a precompiled framework and came accross this project on github:
https://github.com/danomatika/ofxLua
There is an Ios version of boost included in the lib section. So I tried using it in my project
but now when I build my project I am getting these errors:
Undefined symbols for architecture i386:
"vtable for boost::filesystem::detail::utf8_codecvt_facet", referenced from:
(anonymous namespace)::path_locale() in boost(path.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"_inflate", referenced from:
MatlabIO::uncompressVariable(unsigned int&, unsigned int&, unsigned int&, std::vector<char, std::allocator<char> > const&) in MatlabIO.o
"_inflateEnd", referenced from:
MatlabIO::uncompressVariable(unsigned int&, unsigned int&, unsigned int&, std::vector<char, std::allocator<char> > const&) in MatlabIO.o
"_inflateInit_", referenced from:
MatlabIO::uncompressVariable(unsigned int&, unsigned int&, unsigned int&, std::vector<char, std::allocator<char> > const&) in MatlabIO.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I also want to make clear that I installed boost using
sudo port install boost
and under my xcode project I am not linking to /usr/local/include/boost/ or something like that. It seems that it is compiling with incorrect architecture.
Any solution for this? Maybe the framework isn't compiled for Ios? Or is my project not referencing the correct version
You can use the BOOST 1.57.0 with ofxiOSBoost static libraries and headers:
https://github.com/danoli3/ofxiOSBoost
Releases for libc++ (c++11), libstdc++.
All build scripts are in the /scripts folder (updated Peter Goodliffe script)

Resources