MonoMac 平台与框架的互操作
我有使用 DllImport 属性与非托管程序集对话的代码。在 OS X 中,该程序集作为框架安装。
[DllImport("libraryname", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();
然而,这会在 Mono 中抛出 DllNotFoundException,大概是因为它无法解析框架。
我查看了Mono文档: http://www.mono-project.com/Interop_with_Native_Libraries
他们里面有这个小金块:
Mac OS X 平台有一个 lib 前缀和一个 .dylib 后缀,除非 它们是一个框架,在这种情况下它们是一个目录,事情就这样了 更复杂。
但它们不包含任何关于如果它是一个目录我应该做什么的信息(据我所知)。有人有这样做的经验吗?
I have code that uses the DllImport attribute to talk with an unmanaged assembly. In OS X, this assembly is installed as a framework.
[DllImport("libraryname", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();
However, this throws a DllNotFoundException in Mono, presumably because it has not been able to resolve the framework.
I looked in the Mono documentation: http://www.mono-project.com/Interop_with_Native_Libraries
They have this little nugget in there:
Mac OS X platforms have a lib prefix and a .dylib suffix, unless
they're a Framework, in which case they're a directory and things get
more complicated.
But they don't include any info (as far as I could find) about what I should do if it is a directory. Anyone has experience doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想与系统框架进行互操作,那么这个解决方案非常简单,因为它的位置永远不会改变。
例如,如果要访问 CoreFoundation 框架中的 CFRelease 函数,请使用:
Mono 加载器将毫无问题地加载框架。
This solution is pretty simple if you want to interop with a system framework as its location never changes.
For example, if you want to access the
CFRelease
function in theCoreFoundation
framework, use:The Mono loader will load the framework without problem.