c++iosxamarinlinkerxamarin.ios-binding

Native linking error on xamarin ios binding


I am writing a wrapper that bind to an iOS SDK using the P/Invoke as Sharpie was not able to generate a compilable code for this SDK.

When compiling the iOS App with the wrapper project referenced I am having many linking issues such as this one :

MTOUCH: error MT5210: Native linking failed, undefined symbol: std::locale::classic(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. MTOUCH: error MT5210: Native linking failed, undefined symbol: std::__throw_bad_cast(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. MTOUCH: error MT5210: Native linking failed, undefined symbol: std::invalid_argument::invalid_argument(std::string const&). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (Please find the complete log on this complete log file.)

The extra mono touch argument passed from the iOS project are described below:

-cxx -v -gcc_flags "-L${ProjectDir} -lstdc++ -lresolv -liconv -lxml2 -lz -ObjC -force_load ${ProjectDir}/Libs/libcrypto.a" -cxx -v -gcc_flags "-L${ProjectDir} -lstdc++ -lresolv -liconv -lxml2 -lz -ObjC -force_load ${ProjectDir}/Libs/libssl.a" -cxx -v -gcc_flags "-lstdc++ -lresolv -liconv -lxml2 -lz -ObjC -L${ProjectDir} -framework Security -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework CFNetwork -framework Accelerate -framework AudioToolbox -framework CoreAudio -framework Foundation -framework CoreGraphics -framework UIKit -force_load ${ProjectDir}/Libs/libsipwrapper.a -dead_strip -all_load"

The SDK is composed of three libraries : libcrypto.a, libssl.a and libsipwrapper.a.

Following many articles/posts on the internet, it is recommended to add add the standard library such as -lstdc++, lz, and ObjC, but this not seems to work on my case.

I have also tried to create a Binding Project that includes the three libraries and the wrapper code, the content added to the linkwith files seems like that :

[assembly: LinkWith ("libsipwrapper.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Arm64, Frameworks = "CoreVideo CoreMedia AVFoundation CFNetwork Accelerate AudioToolbox CoreAudio Foundation CoreGraphics UIKit", ForceLoad = false, SmartLink = true, IsCxx = true, LinkerFlags = "-lstdc++ -lresolv -liconv -lxml2 -lz -ObjC")]

The problem was not resolved and I continue to have the described linking errors.


Solution

  • After two days of wasted time, I finally got it, to be clear, it's not evident to guess the parameters to pass to touch, to link correctly a library built by a tier only by yourself. To simplify the task, I have compiled the demo app provided by the SDK provider and used Xcode to compile the demo and gets the parameters sent by Xcode to clang++. this helped me to figure out the parameters to send to monotouch:

    --compiler:clang++ -cxx -v -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -force_load ${ProjectDir}/Libs/libcrypto.a" -cxx -v -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -force_load ${ProjectDir}/Libs/libssl.a" -cxx -v -gcc_flags "-dead_strip -lresolv -liconv -stdlib=libstdc++ -fobjc-arc -fobjc-link-runtime -framework CoreMedia -framework CoreVideo -framework AVFoundation -framework CFNetwork -framework AudioToolbox -framework CoreAudio -lz -lxml2 -framework CoreGraphics -framework UIKit -framework Foundation -L${ProjectDir} -force_load ${ProjectDir}/Libs/libsipwrapper.a"

    Hope this will help other guys.

    (Check the two points described by @NyxSway below are also very important)