如何在Mono(适用于Android)(monodroid)和MonoTouch中使用本机C ++库 [英] How to use native C++ libraries in Mono for Android (monodroid) and MonoTouch

查看:72
本文介绍了如何在Mono(适用于Android)(monodroid)和MonoTouch中使用本机C ++库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用Mono for Android和MonoTouch来构建可以利用我拥有的大量C ++本机库的移动应用程序感兴趣.我可以获取有关如何调用方法或将代码合并到iOS或Android上最终移动应用程序中的一些具体说明吗?

I am interested in using Mono for Android and MonoTouch to build mobile applications that can make use of a large number of C++ native libraries that I have. Can I get some specific instructions on how to call methods or incorporate the code into my final mobile app on iOS or Android?

我已经在线查看了Xamarin文档,对于作为移动应用程序编程的新手来说,这对我来说是个谜( MonoTouch ).如果要在Visual Studio中构建Monodroid应用程序(这是我最熟悉的应用程序),我需要从MonoDroid程序中调用本机函数的具体步骤是什么.对于C库,我可以以.DLL(动态)或.LIB(静态)形式进行编译.我还对动态库不能用于移动应用感到印象深刻.

I have looked at the Xamarin documentation online it is pretty cryptic to me as someone who is new to programming mobile apps (Mono for Android and MonoTouch). In the case of building a monodroid app in Visual Studio (which is what I am most familiar with), what are specific steps I need to call a native function from my MonoDroid program. For the C libraries, I can compile in either .DLL (dynamic) or .LIB (static) form. I am also under the impression that dynamic libraries cannot be used for mobile apps.

推荐答案

从理论上讲,可以使用P/Invokes绑定C ++库,但这并不是特别好的方法(因为您将绑定到错误的函数名,这是非常难以理解的,并且可能会在编译器/操作系统之间发生变化.

It is theoretically possible to bind C++ libraries using P/Invokes, but this is not a particularly nice way (since you will be binding to the mangled function names, which are quite unintelligible and will likely change between compilers/OSes).

访问C ++库的推荐方法是创建一个C API并使用P/Invoke(您可以在网上找到很多有关如何进行P/Invoke的信息,这里是一个开始的地方: http://mono-project.com/Dllimport ).

The recommended way of accessing C++ libraries is to create a C API and use P/Invoke (you can find a lot of information about how to do P/Invoking on the web, here is one place to start: http://mono-project.com/Dllimport).

此外,对于MonoTouch,无法使用动态库(这是Apple的限制),您必须使用静态库.我不知道Android版Mono是否有这样的限制.

Also, for MonoTouch it is not possible to use dynamic libraries (this is an Apple restriction), you have to use static libraries. I do not know if there are any restrictions like this for Mono for Android.

这篇关于如何在Mono(适用于Android)(monodroid)和MonoTouch中使用本机C ++库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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