为什么DllImport不能与"__Internal"一起使用? [英] Why DllImport doesnt work with "__Internal"?
问题描述
我有C ++共享库,可以为Linux和Windows导出方法int MyFunc()
.
I have C++ shared library which export method int MyFunc()
for both Linux and Windows.
从C#中,我确实使用以下签名调用MyFunc
.
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();
此代码在Windows上工作正常,但在linux内部会抛出异常EntryPointNotFound
.
This code works fine on windows but inside linux this throw an exception EntryPointNotFound
.
我用-rdynamic选项编译了我的C ++库,我可以看到MyFunc被导出为带有nm的D标志,但这也无济于事.
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.
如果我只是将DllImport(@"__Internal"
更改为DllImport(@"mys.so"
而没有任何更改,则可以在linux上正常工作,但随后我必须在Windows中使用DllImport(@"mys.dll"
,这会破坏代码的跨兼容功能.
所以我想避免这种情况.
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.
我没有看到为什么__Internal
在Linux上无法运行的任何错误.
请注意,我正在使用单声道.
I don't see any mistake that why __Internal
isn't working on Linux.
Note that I'm using mono.
有人知道为什么在Linux上不起作用吗?
Any idea why this is not working on Linux ?
推荐答案
您可以在Windows和Linux上使用它:
You can use this on both windows and linux:
[DllImport ("mys")]
将根据平台添加适当的扩展名(这对.NET和mono均适用).
The appropriate extension will be added according to the platform (and this works on both .NET and mono).
这篇关于为什么DllImport不能与"__Internal"一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!