Reputation: 1238
I have created a Cocoa Touch Static Library using Xcode 4 and I want to use it in a MonoTouch project. How do I proceed?
Here is the content of my Static Library :
MyClass.h
MyClass.m
I built using "Build For Archiving" after following THIS BLOG POST and I took the libMyLib.a it generated and added it to a new MonoTouch Binding Project.
Then I replaced the content of libMyLib.linkwith.cs, because THIS BLOG POST said so.
[assembly: LinkWith ("libMyLib.a", LinkTarget.ArmV6 | LinkTarget.ArmV7 | LinkTarget.Simulator, ForceLoad = true, Frameworks="CoreGraphics QuartzCore UIKit")]
Then I added this to ApiDefinition.cs
I left StructsAndEnums.cs empty.
Then I built with Release and took the dll from the bin folder and added it to the root of a MonoTouch iPad project, and added it to the references.
Then, after following the instructions in THIS ARTICLE, I set the mtouch arguments to this
-gcc_flags "-L${ProjectDir} -lMyLib -force_load -ObjC"
Then I tried to run the project and I got this error in the Build Output
error MT5201: Native linking failed. Please review user flags provided to gcc: "-L/Users/herpderp/Projects/TestProject/TestProject" "-lMyLib" -force_load "/Users/herpderp/Projects/TestProject/TestProject/libMyLib.a" "-L/Users/herpderp/Projects/TestProject/TestProject" "-lMyLib" "-force_load" "-ObjC"
Upvotes: 4
Views: 1774
Reputation: 32694
This directory contains a full sample showing various ways of integrating Objective-C libraries with MonoTouch:
https://github.com/xamarin/monotouch-samples/tree/master/BindingSample
Upvotes: 1
Reputation: 43553
The error message for MT5201 tells you there was an error while doing the native link step. That's 100% sure. The second part ask to to review your gcc_flags
, which is the most common reason, for the failure. However it's not 100% sure this is the issue. When you seek help you should always paste the lines above any error (as they might be useful).
The error is likely about the duplication of the options given to the native linker. This occurs because you did supplied them twice (i.e. in your binding project and in your main project).
From the Binding Objective-C Types article you linked:
Or you can take advantage of the assembly-level LinkWithAttribute, that you can embed in your contract files...
It means the additional mtouch arguments are not needed with you use LinkWith
attribute. Since you're using this way (the best one :-) to bind your static library you can skip this step (from your main project).
By doing so you do yourself (and anyone using your library) a favor since they are less risky to get out-of-sync (e.g. library update or different build configuration).
Upvotes: 1