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

查看:20
本文介绍了在 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++ 库使用符号处理.虽然理论上您可以对重整符号进行 pinvoke,但这不是一个好主意,因为重整是特定于编译器的.

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天全站免登陆