Why can't Unity use DLLImport twice for overloaded functions?

I’ve come across an issue where a library uses DLLImport two times for a function that is overloaded. I am building for iOS. Unity throws this when I try to build “Error building Player: SystemException: Duplicate native method found : BASS_MIDI_StreamCreateFileMemory. Please check your source carefully.”

I did a simple example with my own functions (where I was careful to not use the same parameters), and Unity refuses to compile. Is this only a limitation for ios? It seems to build OK for OSX.

Here is the example .mm file

extern "C"
{
	int StreamCreateFileMemory(bool mem, IntPtr memory, long offset, long length, int flags, int freq)
	{
		return 0;
	}
	
	int StreamCreateFileMemory(bool mem, byte[] memory, long offset, long length, int flags, int freq)
	{
		return 0;
	}
}

Here is the .cs

using UnityEngine;
using System.Collections;

using System;
using System.Runtime.InteropServices;

public class tests : MonoBehaviour 
{
	[DllImport("__Internal"]
	private static extern int StreamCreateFileMemory([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory, long offset, long length, int flags, int freq);
	
	[DllImport("__Internal")]
	private static extern int StreamCreateFileMemory([MarshalAs(UnmanagedType.Bool)] bool mem, byte[] memory, long offset, long length, int flags, int freq);
}

Is there any way around this silly design issue? Unity should be smart enough to handle this if other projects using the MonoFramework are capable.

I could be wrong as my C isn’t exactly up to date, but I don’t believe C method overloading exists in a normal context. I don’t think it would be worth your time and effort to create such functionality yourself, so your best bet is to just overload your C# methods, and then call the corresponding C method accordingly.

It sounds like the problem is compiling in Unity, and not xcode. If this is the case, you could simply write a wrapper class plugin and call that. Ie: instead of calling the closed source plugin directly from unity, make another native plugin and call it via that. I’m not too up on plugin development syntax and my Unity is frozen atm so this probably won’t compile, but something like this:

public class tests : MonoBehaviour {
    [DllImport("__Internal"]
    private static extern int StreamCreateFileMemoryWithIntPtr([MarshalAs(UnmanagedType.Bool)] bool mem, IntPtr memory, long offset, long length,     int flags, int freq);

    [DllImport("__Internal")]
    private static extern int StreamCreateFileMemoryWithByteArray([MarshalAs(UnmanagedType.Bool)] bool mem, byte[] memory, long offset, long length, int flags, int freq);

}

extern "C" {
    int StreamCreateFileMemoryWithIntPtr(bool mem, IntPtr memory, long offset, long length, int flags, int freq)
    {
       return StreamCreateFileMemory(mem, memory, offset, length, flags, freq);
    }

    int StreamCreateFileMemoryWithByteArray(bool mem, byte[] memory, long offset, long length, int flags, int freq)
    {
       return StreamCreateFileMemory(mem, memory, offset, length, flags, freq);
    }
}