Binding iOS Static Library to Xamarin.iOS and using the dll - ios

I am able to successfully create dll file for my Objective-C static library. But when I am try to reference that dll from Xamarin.iOS application and compiling, it is giving me lot of error like...
Error MT5210: Native linking failed, undefined symbol: _AudioFileClose. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5210)
Error MT5210: Native linking failed, undefined symbol: std::ios_base::Init::Init(). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5210)
Error MT5202: Native linking failed. Please review the build log. (MT5202)
After this, I tried to link my .a library using Addtional mtouch Arguments. After adding those arguments, I am getting the new error.
Could not parse the command line arguments: Cannot bundle unregistered option '-o'.
Could someone please help me in resolving this issues.

As Stephane mentioned, there's a IsCxx property on the LinkWithAttribute that you can set to specify that the .a library is a c++ library. That'll solve the std::ios_base::Init::Init() error.
To solve the undefined symbol: _AudioFileClose error, you might try adding the CoreAudio or perhaps AudioToolbox framework to the list of frameworks to link against:
[assembly: LinkWith (..., IsCxx = true, Frameworks = "CoreAudio AudioToolbox")]
Hopefully even if that doesn't quite work, it'll get you headed in the right direction.

Finally figured out the error!!
[assembly: LinkWith (..., IsCxx = true, Frameworks = "CoreAudio AudioToolbox", LinkerFlags = "-lstdc++ -lz" )]
In iOS Binding Projet
Options > Build > Compiler > Addition Arguments
-cxx -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -lMylibrary -force_load ${ProjectDir}/libMylibrary.a”
In my demo application
Options > iOS Buidl > Addtional mtouch Arguments
--gcc_flags="-stdlib=libstdc++"
By giving the proper flags in all the places it resolved my issue.

I resolved this problem installing the new version of Xcode. (now 7.1)
The error is misleading but now it works!

Related

Manual import of Twilio into Swift

I'm building a framework target to be used across multiple apps I am developing and I'm trying to include the Twilio SDK (TwilioCommon & TwilioConversationsClient) in this common framework target.
To do so, I had to create a modulemap to define a module from the headers. Ok, great. Everything seems to work fine. Except I'm getting an excessive number of warnings when following this model:
ld: warning: ignoring linker optimzation hint at _cftmdl_128_neon+0xF0 because ldrInfoC.offset == 0
ld: warning: ignoring linker optimzation hint at _cftmdl_128_neon+0xFC because ldrInfoC.offset == 0
ld: warning: ignoring linker optimzation hint at _cftmdl_128_neon+0x108 because ldrInfoC.offset == 0
....
....
I believe I've adhered to the Manual install for iOS page fairly well and I've created a minimal project on github to replicate this behavior.
Anyone able to spot mistakes? Is this a bug in the way the library was linked?
Versions and things:
XCode 7.2.1, Swift 2
TwilioCommon 0.2.0
TwilioConversationsClient 0.22.0
This question is remarkably similar to this one:
How do I resolve linker warning "ignoring linker optimzation hint at" in XCode?
If you're compiling the WebRTC library by yourself using build
scripts, the warnings are generated because of a missing parameter in
GYP_DEFINES.
In order to fix the warnings, the WebRTC library needs to be compiled
again with the parameter clang_xcode=1 in the GYP_DEFINES setting,
like below (only an example):
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=arm64
clang_xcode=1" More about the issue can be found here, on the Chromium
forums: https://bugs.chromium.org/p/webrtc/issues/detail?id=5182
--
If you're not compiling the WebRTC library yourself, and instead
installing the WebRTC library from a 3rd party source, I don't believe
there is a fix as the warnings are stemming from the static library.

Global Function from framework gives Undefined symbols linker error

I am trying to use a framework in my app (CoreBitcoin). Followed the build instructions from the README and copied the framework directory into my project. I also linked it in the Build Phases -> Link Binary With Libraries.
Now the code compiles and works
#import <CoreBitcoin/CoreBitcoin.h>
// I can instantiate class objects and use functions such as
BTCKey *newKey = [[BTCKey alloc] init];
[newKey setPublicKey: nil];
But if I try to use any global function such as
BTCDataFromBase58(#"anystring");
The linker throws an error:
Undefined symbols for architecture i386:
"BTCDataFromBase58(NSString*)"
I have looked around and tried many solutions to fix this error: the framework is in my search paths, I disabled bitcode and fiddled a bunch with the project build settings, however, it is strange that the undefined symbols are specific to global functions.
I am using Xcode 7.2, and get the warning:
(CoreBitcoin library path) was built for newer iOS version (9.2) than being linked (7.1)

Xamarin - can no longer debug on device -error MT5211

Until the most recent upgrade I could debug on a device. I now get the following errors:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_ZipArchiveDelegate", referenced from:
objc-class-ref in registrar.armv7.o
_OBJC_CLASS_$_MiniZip_ZipArchive_ZipArchive__ZipArchiveDelegate in registrar.armv7.o
"_OBJC_METACLASS_$_ZipArchiveDelegate", referenced from:
_OBJC_METACLASS_$_MiniZip_ZipArchive_ZipArchive__ZipArchiveDelegate in registrar.armv7.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error MT5211: Native linking failed, undefined Objective-C class: _OBJC_CLASS_$_ZipArchiveDelegate. If '_OBJC_CLASS_$_ZipArchiveDelegate' is a protocol from a third-party binding, please check that it has the [Protocol] attribute in its api definition file, otherwise verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
error MT5210: Native linking failed, undefined symbol: _OBJC_METACLASS_$_ZipArchiveDelegate. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
error MT5202: Native linking failed. Please review the build log.
I've cleaned, and rebuilt but with no avail. Any ideas?
It turns out this error is caused by the improved strictness of the new default static registrar:
http://docs.xamarin.com/releases/ios/xamarin.ios_7/xamarin.ios_7.2/#1
http://docs.xamarin.com/guides/ios/advanced_topics/registrar/#Protocols_must_have_the_Protocol_attribute
You can work around the problem temporarily by requesting that Xamarin.iOS use the legacy registrar. To do this, add "--registrar:legacy" under "Project Options -> iOS Build -> Additional mtouch arguments".
The components team has also contacted the authors of the ZipArchive component to let them know about the issues with the new registrar, but they have not yet replied. In case the they do not provide an update soon, you can look at transitioning to an open-source binding for the same library written by the Xamarin components team [1]. One caution with this binding is that the method and class names might be different from the ones in the ZipArchive component, and the namespaces are definitely different. So you will need to update the names in your app accordingly.
[1] https://github.com/mono/monotouch-bindings/tree/master/ZipArchive
Having the exact same issue. But both on zipArchive and SDWebImage.
Uninstalled-re-installed xamarin. Did not help.
Created a solution from scratch, added zipArchive and added to the using section.
The project does not build for device. But building for simulator is fine.
Emailed Xamarin support for help.

Xamarin iOS - Binding Project - Warning

Am using
Xamarin Studio - 4.0.4 (build 2)
Mono - 2.10.11
Xamarin.iOS - 6.3.5.43
Mac OS X - 10.8.2
When building the wrapper binding class, I get a warning saying 'System.Runtime.CompilerServices.ExtensionAttribute' is present in multiple assemblies. Its just a warning, but builds the .dll file.
Target GenerateBindings:
Tool /Developer/MonoTouch/usr/bin/btouch execution started with arguments: /unsafe /d:DEBUG ApiDefinition.cs /s:StructsAndEnums.cs /tmpdir:obj/Debug/ios/ /sourceonly:obj/Debug/ios//sources.list
warning CS1685:
The predefined type System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies. Using definition frommscorlib'
/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll (Location of the symbol related to previous warning)
/Library/Frameworks/Mono.framework/Versions/2.10.11/lib/mono/2.0/System.Core.dll (Location of the symbol related to previous warning)
But when using the created binding class in another project, it gives the error saying
Compiling to native code -
'error MT5202: Native linking failed. Please review the build log.'
In the build log
ld: file not found: /var/folders/w4/xsz8x8vx0_51hjxj474r1_fxhlq7x3/T/tmp9aef74.tmp/libPrint.a
collect2: ld returned 1 exit status
Note : libPrint.a is my static library
-Update-
When binding the libPrint.a file to the wrapper class, the .a file should be added to the project and not inside the 'Resources' folder. This solved the issue am facing.
Does libPrint.a support the architecture you are building your iOS project for?
IOW, if you are compiling for Simulator, your libPrint.a needs to support i386.
If you are compiling for device, it needs to support whatever ARM arch you are targeting.
The warning is because of the ambiguity for System.Runtime.CompilerServices.ExtensionAttribute' in multiple assemblies.
Keeping the warning aside, the real problem is when adding libPrint.a file.
Its a small silly mistake. The docs of xamarin clearly explain it.
It should be added to the project and not inside the 'Resources' folder.
This solved the error I'm getting when using the .dll file for a project.

Linker error compiling PDFKit

I am trying to integrate PSPDFKit for iOS in my project and I have not been yet able to success. After downloading the Demo version, adding the framework to my project, adding all the required libraries and placing
#import <PSPDFKit/PSPDFKit.h>
on the 'prefix' file, I get an linker error:
ld: section __objc_const (address=0x00613EA8, size=4651232504) would make the output executable exceed available address range for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
NOTE: My project uses PSTCollectionView and I have successfully compiled PSPDFKit on a test project (created only for that effect).
I would really appreciate any help. Thanks in advance.
Apparently, you have too many included files in your PCH file.
Try removing some of them, and include those files only where you need them, not globally.
As far as I understand it, this is a bug in Apple's compiler/linker chain. Please file a radar at radar.apple.com with your failing project. A workaround is to use the source code as a subproject instead of the precompiled binary.
As soon as I can get my hands on such a project, I can experiment with the settings to see if there's any workaround. Seems to only happen under very specific combinations with other 3rd party code.

Resources