How to use dlopen on OS X?

I’m working on making a set of native libraries for various platforms (OS X, Windows, iOS, and Android). On OS X, I have a bundle. For Windows, I opened the native dll with the following code:

        internal static void LoadNativeDll(string FileName)
            if (lib != IntPtr.Zero)
	        lib = LoadLibrary(FileName);
            if (lib == IntPtr.Zero)
                Debug.LogError("Failed to load native library! ");

        [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
        internal static extern IntPtr LoadLibrary(
    		string lpFileName

I am trying the following for OS X:

	 	public static IntPtr LoadLibrary(string fileName) {
			return dlopen(fileName, RTLD_NOW);
		public static void FreeLibrary(IntPtr handle) {
		public IntPtr GetProcAddress(IntPtr dllHandle, string name) {
			// clear previous errors if any
			var res = dlsym(dllHandle, name);
			var errPtr = dlerror();
			if (errPtr != IntPtr.Zero) {
				throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr));
			return res;
		const int RTLD_NOW = 2;
		private static extern IntPtr dlopen(String fileName, int flags);
		private static extern IntPtr dlsym(IntPtr handle, String symbol);
		private static extern int dlclose(IntPtr handle);
		private static extern IntPtr dlerror();

This is based on a blog I found. OS X is UNIX based, but there does not appear to be a version of compiled for OS X and thus get the error:


Even if one did exist, would it need to be packaged within the asset folder? MacMono seems to be an option that used to exist. Help, how do people load libraries in OS X?

I fixed this by using libdl.dylib instead of . I got this idea from a Wikipedia article. I also wrote a blog with more details.