链接到MonoTouch中的C ++本机库 [英] Linking to a C++ native library in MonoTouch

查看:96
本文介绍了链接到MonoTouch中的C ++本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关将本机库链接到MonoTouch的信息,特别是以下文档:

I am reading up about linking native libraries into MonoTouch, specifically this documentation:

http://monotouch.net/Documentation/Linking_Native_Libraries

此处描述了链接到C库的过程.是否还可以从MonoTouch链接到C ++库?我对MonoTouch尤其是对于导入库非常陌生,因此,如果确实有可能,我将对尝试导入C ++库可能遇到的问题提供任何建议,我将不胜感激.将C ++库包装到Objective-C库中,然后使用btouch导入这是否是一个好方法?还是有更简单的方法?请记住,最好将我对C ++的知识(以及该问题的Objective-C)描述为危险". ;)

Here it describes linking to C libraries. Is it also possible to link to C++ libraries from MonoTouch? I am very new to MonoTouch and particularly to importing libraries, so I would appreciate any advice about problems I may face trying to import a C++ library, if this is indeed possible. Would wrapping the C++ library in an Objective-C library and then using btouch to import this be a good route to take? Or is there an easier approach? Bearing in mind that my knowledge of C++ (and Objective-C for that matter) can best be described as "dangerous". ;)

我问的原因是我需要使用Sybase的C ++ API来访问其Ultralite数据库.我设法获得了一个示例应用程序,该示例应用程序可以通过Objective-C访问Xcode中的Ultralite C ++ API.但是现在我正尝试将此示例移植到MonoTouch.可以在这里找到示例应用程序:

The reason that I ask is that I am needing to make use of a C++ API from Sybase to access their Ultralite database. I have managed to get a sample application that accesses the Ultralite C++ API working in Xcode, with Objective-C. But now I am trying to port this sample to MonoTouch. The sample application can be found here:

https://github.com/BruceHill/Ultralite-Names-Sample-ObjC

有关Xcode的Sybase文档,提到了以下有关在Xcode中使用API​​的信息:

The Sybase documentation for Xcode mentions the following, with reference to using the API in Xcode:

本教程使用UltraLite C ++ API.为了消除强制转换为C类型的需要,请将源代码编译为C ++.要将项目编译为C ++:

This tutorial uses the UltraLite C++ API. In order to eliminate the need to cast to C types, compile the source as C++. To compile the project as C++:

  1. 在在构建设置中搜索"框中,输入将源编译为".
  2. 从值"字段中的选项中选择Objective-C ++

在MonoTouch中使用此API有什么含义?

What are the implications of this for working with this API in MonoTouch?

推荐答案

您当然可以使用C ++ api,但是您需要将其包装在C api或ObjC + btouch api中才能与之交谈这.调用C api使用PInvoke,而C ++库使用符号修饰.从理论上讲,您可以使用错位的符号,但这不是一个好主意,因为错位是特定于编译器的.

You can certainly use a C++ api, but you will need to either wrap it in a C api, or a ObjC+btouch api to be able to talk to this. Invoking C api's uses PInvoke, and C++ libraries use symbol mangling. While theoretically you could pinvoke to the mangled symbol, this isn't a good idea as the mangling is compiler specific.

这篇关于链接到MonoTouch中的C ++本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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