aybe / aubio.net

aubio for .NET
13 stars 9 forks source link

macOS and Android|iOS : System.DllNotFoundException: kernel32 #4

Closed sushihangover closed 6 years ago

sushihangover commented 6 years ago
Unhandled Exception:
System.DllNotFoundException: kernel32
  at (wrapper managed-to-native) Aubio.NET.Win32.NativeMethods.RemoveDllDirectory(intptr)
  at Aubio.NET.AubioObject+Destructor__.Finalize () [0x00002] in <98b0c1708c7b487493725149fd66588f>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: kernel32
  at (wrapper managed-to-native) Aubio.NET.Win32.NativeMethods.RemoveDllDirectory(intptr)
  at Aubio.NET.AubioObject+Destructor__.Finalize () [0x00002] in <98b0c1708c7b487493725149fd66588f>:0

The use of native Win32 methods is an issue when using on non-Windows platforms.

    [SuppressMessage("ReSharper", "InconsistentNaming")]
    private sealed class Destructor__
    {
        ~Destructor__()
        {
            // TODO this is not triggerred, at least on UWP

            if (!NativeMethods.RemoveDllDirectory(Cookie))
                throw new Win32Exception();
        }
    }
aybe commented 6 years ago

Thanks for the report,

Ok ... it's been a few months I haven't touched the project but I've been able to craft something, however :)

See the updated README at https://github.com/aybe/aubio.net/blob/develop/README.md.

Let me know how it goes,

PS I believe using aubio instead of aubio.dll in imports should be supported in your platform, too.

sushihangover commented 6 years ago

@aybe Thanks for the reply. In general aubio.net (develop batch) works fine on Xamarin.iOS|Android|Mac once I stripped the native kernel32 methods out (plus the copy directory routine/cookie code that fails on Android|iOS). Mono handles a wide variety of fall-backs (via ABI/ARCH/path sniffing) of the DLLName-based name, so aubio.dll will actually load libaubio.so, etc...

On macOS, the only real issue is setting the DYLD_FALLBACK_LIBRARY_PATH env. var so the libaubio.dylib can be found and forcing 64bit as 32bit is close to be being removed from macOS completely (I am only creating a 64bit libaubio.dylib vs. a "fat" 32/64 version and thus the CIL needs to be flagged as x64 so console-based .exe run with Mono will default to the Mono64 runtime).

There are a few areas that I have not looked into yet, i.e Tempo.Period overflows on Android and I have not chased down the issue (assuming it is a NDK 32bit int issue as it is fine(?) on 64bit platforms).

After I chase those issues down, I need to create some shell wrappers that will run on the Xamarin platforms so I can comply with the GPL licensing (need to do the same thing with a static version of ffmpeg, yuk 😭 ).

aybe commented 6 years ago

From what I remember when I wrote that months ago, was to not trust aubio online docs, they are outdated and riddled with inexact and missing information.

I ended up browsing/debugging freshly built sources and fix/improve my code on the go, just remember that there are bugs and inconsistencies in aubio; so having the sources next to your app can give you a hint on where the problem comes from.

I did report some of the bugs, but it seems that aubio has grown to such out of control beast that the authors are reluctant to make changes and fix some of them (understandably).

Note: I am not affiliated with aubio at all, just wrote that (mostly) for fun. Regarding licensing, do whatever you want with my code (Aubio.NET), and if you have written some cool app using it I'll happily linkback to it.

oh, and good luck with ffmpeg because you'll need definitely some :)