为什么 DllImport 不能与“__Internal"一起使用? [英] Why DllImport doesnt work with "__Internal"?

查看:24
本文介绍了为什么 DllImport 不能与“__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 和单声道).

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

这篇关于为什么 DllImport 不能与“__Internal"一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆