从 c# 调用 UNIX 和 Linux 共享对象文件 .so [英] Calling UNIX and Linux shared object file .so from c#

查看:25
本文介绍了从 c# 调用 UNIX 和 Linux 共享对象文件 .so的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 C# P/Invoke 调用用 C 编写并在 Unix 上构建的共享对象文件?

Is there a way for a Shared Object file written in C and built on Unix to be called from C# P/Invoke?

或者我需要使用 Java 或类似的东西吗?

Or do I need to use Java or something like that?

推荐答案

Mono 能够从基于 dlopen(3) 构建的 C# 中与本地库集成.您只需使用带有库名称的 DllImport 语句(即libform.so.5"),然后使用友好的 C# 类来包装本机代码和数据类型,该类负责处理所有低级内容.此页面 有一个很好的概述,其中包含有关如何处理封送指针和其他不安全类型的大量信息.

Mono has the ability to integrate with native libraries from within C# built on top of dlopen(3). You just have to use the DllImport statement with the name of the library (i.e. 'libform.so.5'), then wrap the native code and data types with a friendly C# class that takes care of all the low-level stuff. This page has a good overview with lots of information on how to deal with marshaling pointers and other unsafe types.

一旦你编写了你的​​包装类,你就可以直接使用它,而不必担心它在下面使用了一个本地共享库.

Once you've got your wrapper class written, you can just use that without worrying about the fact that it's using a native shared library underneath.

这篇关于从 c# 调用 UNIX 和 Linux 共享对象文件 .so的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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