[Mono-dev] DllImport("__Internal") and libMonoPosixHelper static build

Jonathan Pryor jonpryor at vt.edu
Mon Apr 16 17:32:52 UTC 2012

On Apr 12, 2012, at 3:43 AM, ralphbariz wrote:
> I'm trying to compile a static one binary mono(Because the target system has an incompatible loader).

What platform is this? What kind of loader does your target system have? Does it have any shared library loader?

> After a few tries, I got also this, changed all DllImport(MPH) calls in Mono.Posix.dll to DllImport("__Internal"),

DllImport("__Internal") requires that the target platform (1) support dlopen(NULL, mode) to open the main executable, and (2) that dlsym() be able to find symbols within the main executable.

Note that (1) is not true for Windows, so [DllImport("__Internal")] will not work on Windows (iirc).

> it still gives me a TypeInitializationexception when I try to access the stat symbol of the libMonoPosixHelper.

That's odd; Syscall.stat() P/Invokes Mono_Posix_Syscall_stat(), not stat():


Mono_Posix_Syscall_stat(), meanwhile, is just a simple wrapper around stat(2):


If your program is dying because Mono_Posix_Syscall_stat() can't be found, then the problem is probably that dlopen(NULL, mode) is not supported on your platform. If stat() can't be found, then (1) your platform doesn't provide stat(2), or (2) (somehow) your program is being improperly linked and stat() isn't being found.

 - Jon

More information about the Mono-devel-list mailing list