I created a static cocos project in xcode, the entire project consisted of a single .c file called File.c and this function:
int Get10()
{
return 10;
}
I created a target for it called ‘Numbers’ and built the project, which created a libNumbers.a. I moved libNumbers.a to my MonoTouch projects root directory and in the additional mtouch arguments area I added:
-gcc_flags “-L${ProjectDir} -lNumbers -force_load
${ProjectDir}/libNumbers.a”
The code compiled fine.
So in a C# file in my MonoTouch project I added the following:
[DllImport ("libNumbers.a")]
private static extern int Get10 ();
(I’ve also tried doing [DllImport (“Numbers.a”)])
Then during exception a function called Get10(). This throws the following exception:
System.DllNotFoundException: libNumbers.a at (wrapper
managed-to-native) Jabber.BaseGame:Get10 () at Jabber.BaseGame.Draw
(Microsoft.Xna.Framework.GameTime dt) [0x00043] in
/Users/ahmedhakeem/Documents/Projects/goodjabberengine/MyCode/Engine/BaseGame.cs:103
From what I can see it looks like it’s unable to find the dll in question.
One possible cause is that I call the function Get10 (and import it) to a source file in a seperate library project (i.e. not the project I added the additional mtouch arguments). There is no way of adding mtouch arguments to a library project in monotouch which you’re linking in so I don’t think that’s an option.
So any ideas on how to fix this?
If the library is linked with the app when the symbols becomes internal (inside the main app). In this case the correct declaration will be: