I need to create some functions in native code that are called from my MonoTouch app. I've tried a lot of variations to get this working, but I always get, "Error: You should provide one root assembly only" when I try to build.
Here are the steps I've taken to try this:
Create a simple MyFile.cpp file:
extern "C"
{
int TestAdd( int a, int b );
}
int TestAdd( int a, int b )
{
return a+b;
}
Build that into a .a file:
/Developer/Platforms/iPhoneOS.platform/Dev开发者_开发技巧eloper/usr/bin/gcc-4.2 -arch armv6 -c MyFile.cpp
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool -static -arch_only armv6 MyFile.o -o libtest.a
Copy libtest.a into my MonoTouch project's folder and add it to the project.
Under Project Options->iPhone Build, set Extra arguments to "-ltest".
.. and I keep getting "Error: You should provide one root assembly only". I haven't even used the DllImport("__Internal")) attribute or tried to call TestAdd inside my code yet.
What am I doing wrong here?
Your extra arguments are wrong, they should be something like:
-gcc_flags "-L${ProjectDir} -ltest -force_load ${ProjectDir}/libtest.a"
In my case, I changed the name of the base folder which contained .sln file and hence I was getting this error. I changed the root folder back to earlier one and the error got fixed.
精彩评论