是否可以从.NET Core在Linux平台上调用共享库(.so)? [英] Is it possible to call a shared library (.so) on linux platform from .NET core?

查看:1059
本文介绍了是否可以从.NET Core在Linux平台上调用共享库(.so)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道.NET内核的目标是跨平台开发,但是我正在寻找向后兼容性。如果我有一个可用的linux库(也许是旧版),并且希望从用于linux平台的.NET核心应用程序中调用它的功能。有可能吗?

I understand that aim of the .NET core is for cross platform development, but I am looking for backward compatibility. If I have a linux library available (maybe, legacy) and I want its functions to be called from .NET core application for linux platform. Is it possible?

我不是在谈论ASP.NET内核,我需要它用于桌面应用程序。

I am not talking about ASP.NET core, I need it for a desktop application.

推荐答案

查看SWIG。这是包装共享库的一种简单方法,它可以为您生成所有P / Invoke代码,并在.so库和C#代码之间映射任何头文件(认为结构)。我们在要使用的.so库周围创建了一个简单的cpp包装器,然后让SWIG发挥作用。现在,我们有了一个C#库,可以从调用我们的Linux库函数的.Net代码(一个简单的控制台应用程序)中调用。我们已经在运行Ubuntu,CentOS和Debian的Unix主机上的PI上成功地做到了这一点。 http://www.swig.org/

Look at SWIG. It is a simple way to wrap a shared library and it generates all of the P/Invoke code for you as well as maps any header files (think structs) between your .so library and your C# code. We created a simple cpp wrapper around the .so library that we wanted to use and then let SWIG do its magic. We now have a C# library that can call from our .Net code (a simple console app) that invokes our linux library functions. We have done this on a PI, on unix hosts running Ubuntu, CentOS, and Debian with great success. http://www.swig.org/

这篇关于是否可以从.NET Core在Linux平台上调用共享库(.so)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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