Use existing DLL in iOS app through mono framework - ios

For one of my current iOS project, some business logic has been provided to me through a DLL and Native C++ binding code that i have to recompile in a dynamic library (dylib) and then use the DLL through this dynamic library.
Finally the DLL is used like this example:
int main(int argc, char** argv){
RTEnvironnement::CreateRTEnvironnement("../dll/RT.dll");
RT::RT_Facade * mFacade = new RT::RT_Facade();
RT::RT_Data_Projet * mProjet = new RT::RT_Data_Projet();
mProjet->Load_From_XMLFile(argv[1]);
...
Objects RTEnvironnement, RT_Facade, RT_Data_Projet are provided by the binding C++ dynamic lib. I cannot get the code of the base DLL and i have to use the DLL as it is on IOS.
I'm currently studying if mono touch can able my IOS app (basic iOS Objective C based on Xcode ), to launch the DLL that as been build with the standard mono framework. Before purchasing a license, I have to be sure that MonoTouch is able to do this.
Is someone do something similar ? Is there a simplest way to this ?
If i choose to use MonoTouch, can i keep my project in Xcode and just build the dylib in MonoDevelop and then import the lib the Xcode project ?
Thanks for your help.

the DLL that as been build with the standard mono framework.
MonoTouch (like Mono for Android) provide a base class library (BCL) profile that is similar (a superset) to Silverlight. However it's a subset of the whole Mono framework.
As such it's very common that assemblies compiled against the full framework won't work on MonoTouch unless they are re-compiled (against the MonoTouch BCL).
If i choose to use MonoTouch, can i keep my project in Xcode and just build the dylib in MonoDevelop and then import the lib the Xcode project ?
It's more complicated than that (e.g. MonoDevelop won't give you a .dylib). You might be able to google some instructions to do this, however be aware that this scenario is unsupported.
An supported alternative is to make MonoTouch drive the application, load any assemblies you need, expose those and then transfer control to your Objective-C code.

Related

using an ios framework for native c++ code for ios

I have written a c++ library that needs opencv which is an image processing library. I want to now use this c++ library on ios. To do that I am going to copy my code to a mac and build to produce a cocoa touch static library.
Since, this has a dependency on opencv, I downloaded its ios framework. But now I am confused whether a framework can be used from c++ code or just from objective c/c++ ? Do I have to recompile this library so that i get c++ libraries or I can use the framework in my c++ code?
Yes, it can be used with c++. You will have to make sure you Type is set to "Objective C++ Source" for where you are making the framework calls.
I mix my C++ code with frameworks all the time.
Note this goes both ways. If you have Obj-C interacting with C++, you'll need to either have the file be a .mm or be of the "Objective C++ Source" Type.
The Type selection is in the File Inspector for files.

How to organize Android NDK / iOS project

I wrote a game for Android using Android NDK. Core of game logic written in pure C++. So, I want to port it to iOS. I know how to port Java (JNI) wrapping to Objective-C.
My question is how to organize this project on FS? I want to keep a single code base, and I use git (link).
First, note that there should be no need at all do wrap your C++ code: the objective-C extension of the C language is also compatible with C++. So, you can compile your code as "Objective-C++" and directly use C++ classes with Objective-C code.
Second, you can put your code anywhere you wish on the disk. Both eclipse for Android and xcode for iOS will let you include source code into your project from any relative directory.
If you ever need platform-specific native code you can use #ifdef __ANDROID__ for android-specific code inside your C++.

Embedding Mono on iOS

I want to embed mono into my iOS application. I do not want to use MonoTouch. I want to embed mono manually like this:
http://www.mono-project.com/Embedding_Mono
I've have done this successfully on windows, using the above guide and various online examples, here's a good Windows one:
https://github.com/inkdev/Embedded-Mono-Sample
However I'm having trouble getting started on iOS. I know it can be done, companies like Unity3d use it to power their game engine tech. I can't work out how to compile and link mono for iOS nor can I find any good instructions to do so. I've not found any help using search engines, they exclusively seem to turn up articles about MonoTouch (Xamarin's own commercial wrapper around embedding mono into iOS).
Here's a few more noteworthy links:
http://www.mono-project.com/Mono:ARM
http://web.archive.org/web/20090106023130/http://mono-project.com./Mono:Iphone
Is there somewhere I can get precompiled libraries and headers for Mono for iOS, so in my C code I can simply link and include?
Could someone provide and example of how to compile mono for iOS ARM CPUs?
MonoTouch provides a great wrapper around all of the iOS Objective C APIs, however you don't necessarily need all of that, as I understand it should be possible to compile and then embed mono yourself and then use pInvoke to call the few native functions you will need.
Any help would be greatly appreciated, ty!
While not exactly what you are asking for, iOS 7 has added support for scripting with JavaScript. Many people finding this post may want to use this new capability to achieve what you are attempting. Link
As Rolf said, you need to read Mono Licensing document first. Embedding mono on iOS requires special permission from Xamarin.
You need to change several build settings from XCode, and here's what I did.
Open (or Create) iOS project
Add libmonoboehm-2.0.a to your project(You can use another version of .a file)
It's in Library/Frameworks/Mono.framework/Versions/{version}/lib folder
Project -> Build Settings -> Header Search
Add path: /Library/Frameworks/Mono.frameworks/Versions/{version}/include/mono-2.0
Project -> Build Settings -> Library Search
Add path: /Library/Frameworks/Mono.frameworks/Versions/{version}/lib
And, code like this in your iOS application
#include <mono/jit/jit.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/environment.h>
// ....
const char* dllFile = "ABSOLUTE_PATH_TO_DLL_OR_EXE";
domain = mono_jit_init(dllFile);
mAssembly = mono_domain_assembly_open(domain, dllFile);
// ... Do whatever you want :)
Please remember. You need to get license from Xamarin when embedding mono on iOS.
Enjoy :)

Unable to use System.XML.Linq

I am working on a project using Mono for Android. After reading a cross-platform document with Xamarin. I had my data layer in a separate project and was going to move it to my Mono for Android project and then link those files to my Mono Touch project, and one day perhaps a Windows Phone 8 project.
When I moved the code, I am now unable to compile because of the System.Xml.Linq reference. The reference shows in the Mono for Android project, but I am unable to use it. I thought aiming for Froyo may be the problem, but upgrading the project to Gingerbread or Ice Cream Sandwich didn't help.
Does anybody know what I am doing wrong? I am a seasoned .NET developer and am well aware of how references work in project, but this one has me stumped.
The project the original code was working on was targeting the Mono/.NET 4 framework
Is your reference to System.Xml.Linq pointing to the .Net version or the Mono version? The one for Mono will have Version 2.0.5.0.
Also, is the reference to System.Xml.Linq in a Android Class Library/Application or in a regular .Net Class library. If it is a .Net Class library, I would try referencing the library in your Android application as a compiled (dll) reference and not a project reference. It is not a perfect solution, but I have found that this works when I needed to reference libraries that I use across multiple solutions. The reference will generally work out fine, but if there is anything that is not supported in the Mono version, then it can cause issues.
Assuming you have your code in a class library, your best bet may be to create a Mono specific version of your library project. You can import and use the same class files, but just add some Conditional compilation symbols to have it compile properly for Mono. If you are not familiar with this, take a look at how Json.Net or ServiceStack manages code for multiple platforms.

using a C Dll and lib in obj c - ios

I have a C lib and dll file from windows application. No source code with me.
Is it possible to use that in an IOS application.
I have seen mixed responses and am confused.
If we have source code , i think we need to create dylib and then we can use the same after including relevant header file.
Please share any expert ideas to guide me in right direction.
Appreciate your help .
mia
Dynamic Libraries are not permitted on iOS to begin with, but above that, the DLL file format is not recognized by Darwin or the underlying XNU Kernel at all, as the binary format is different.
Windows APIs are not usable on the Darwin OS either (Both Mac OS X and iOS are wrappers around the basic Darwin OS). You will need to rewrite the code from the DLL to use the POSIX and/or Objective-C APIs and compile it as a static library to use it.
You need to get a iOS compatible library, no other way around it. There are several reasons:
iOS doesn't support DLLs as they are windows format, but moreover, you can't use any dynamic library on iOS, as Apple restricts it.
DLLs are usually for intel CPUs, while iOS devices have ARM CPUs.
Most dlls are calling windows APIs - are you sure this one's not?
No. If you all you have is a compiled binary DLL, there is no way to use it on iOS. Unless you happen to have an ARM DLL for the upcoming Windows 8, your DLL contains either x86 or x86-64 machine code (or maybe IA64 if you have a lot of money), which absolutely will not run on iOS devices, which are all ARM architectures. Plus many more reasons.
If you have the source code, you can recompile it for iOS, either directly into your app, as a static library that can be linked in with your app, or as a dynamic library as part of a framework. But in all cases, you need to recompile it from source code using the iOS compiler.
You are going to have to recompile it as a static library (.a file). Apple doesn't allow dynamic libraries except for their own frameworks (so you can't compile it as a dylib).

Resources