I am trying to link a static library (foo.a) - which contains C++ code - in an Xamarin.Android project following the directions found in Xamarin's docs. Neither the "path sniffing method," nor the "Abi element within the project file" method seems to work.
Using either method I get unhandled exceptions when I attempt to call into the library functions:
I/mono( 2591): [ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: ...
I should mention that I have had no trouble linking and calling into this library (built for armv7, armv7s) with my Xamarin.iOS project using the "additional mtouch arguments" -cxx method described here. All of my DLLImports are the same across platforms...
[DllImport(Import.lib, CallingConvention=CallingConvention.Cdecl )]
internal static extern IntPtr FooMethodName(args);
So, what am I missing?
FYI: I am using Xamarin Studio 4.0.5 (build 4), Xamarin.Android 4.6.4 (Business Edition)
Static libraries are created by copying all necessary library modules used in a program into the final executable image. The linker links static libraries as a last step in the compilation process. An executable is created by resolving external references, combining the library routines with program code.
So what is a Static library?? When linked like this the library is called a static library, because the library will remain unchanged unless the program is recompiled. This is the most straight forward way of using a library as the final result is a simple executable with no dependencies.
Xamarin. Android applications use a linker to reduce the size of the application. The linker employs static analysis of your application to determine which assemblies are actually used, which types are actually used, and which members are actually used.
In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.
I realize this question is over a year old, but since I recently had to do exactly this, and hit my head in the same spot, I'll have a go at it anyway...
TL;DR: you cannot link static libraries with Xamarin for Android, you can only link dynamic libraries (.so)
Steps:
extern "C"
{
void my_function(bool someParameter);
}
namespace MyApp
{
public static class MyLibrary
{
[DllImport("libmylibrary", EntryPoint = "my_function")]
public static extern void MyFunction(Boolean someParameter);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With