1

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

http://monotouch.net/Documentation/Linking_Native_Libraries

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". ;)

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

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

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. In the Search in Build Settings box, enter Compile Sources As.
  2. Choose Objective-C++ from the options in the Value field

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

BruceHill
  • 6,954
  • 8
  • 62
  • 114
  • Did you happen to get further with this? I've build the C stubs and C# object wrappers using SWIG and am just trying to get the linking with MonoTouch working at the moment, but if you've solved all this already I wouldn't mind taking a look. – Kenny Dec 17 '13 at 15:18
  • Hi Kenny. Yes, I did get this working a long time ago. I will look at getting the source onto github so you can take a look. – BruceHill Dec 18 '13 at 04:51
  • @BruceHill - did you ever update the solution on GitHub? My friend is working on this exact thing and said it's not in the link from the question... – c_rath Nov 20 '14 at 21:22

1 Answers1

0

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.

Geoff Norton
  • 5,056
  • 1
  • 19
  • 17
  • Thanks, Geoff. I had a feeling that I would have to wrap the C++ api to use it; I was just hoping that there was an easier way because it is a fairly large api to wrap. Well, guess I know what I will be doing this weekend! hehe I think that I will wrap it with ObjC+btouch because I have managed to build a simple _hello world_ library in ObjC and then bind the types with btouch. And I must say, I was very pleased to see how easy btouch was to use. :) It worked on my first attempt! Whoo! :) Thanks again for your help. – BruceHill Mar 09 '11 at 18:32