Why DllImport doesnt work with “__Internal”?

2019-02-27 09:06发布

问题:

I have C++ shared library which export method int MyFunc() for both Linux and Windows.

From C# I do call the MyFunc with following signature.

[DllImport(@"__Internal", CharSet = CharSet.Ansi, EntryPoint = "MyFunc")]
static extern unsafe int MyFunc();
// Later I'm using :
MyFunc();

This code works fine on windows but inside linux this throw an exception EntryPointNotFound.

I have compiled my C++ library with -rdynamic option and I can see MyFunc is exported as D flag with nm but this also didn't help me.

Without any change if I simply change DllImport(@"__Internal" to DllImport(@"mys.so" then will work fine on linux but then I have to use DllImport(@"mys.dll" in windows which this breaks code cross compatible feature.
So I want to avoid this.

I don't see any mistake that why __Internal isn't working on Linux.
Note that I'm using mono.

Any idea why this is not working on Linux ?

回答1:

You can use this on both windows and linux:

[DllImport ("mys")]

The appropriate extension will be added according to the platform (and this works on both .NET and mono).



标签: c# c++ .net mono