How to organize Android NDK / iOS project - ios

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++.

Related

Porting OCaml compiler to iOS with a Swift Package

I'm currently trying to create a Swift Package (or Cocoa Touch Framework or anything that can be imported into an Xcode Swift Project) to wrap the OCaml compiler into an iOS app.
My goal is to allow an iOS app to dynamically build and run OCaml code from the device. (without requiring an external server or whatever else to build and run the code, but do it directly on the device)
Here are resources I used to document myself and find a solution:
The OCaml compiler itself (written in C): https://github.com/ocaml/ocaml
How to Integrate a C Library into an iOS App Written in Swift: https://medium.com/#distillerytech/how-to-integrate-a-c-library-into-an-ios-app-written-in-swift-ef92c0e0d42b
Trying to understand how the port was done for python for ios: https://github.com/holzschu/python3_ios and https://github.com/holzschu/cpython
Compiler from OCaml to Javascript: https://github.com/ocsigen/js_of_ocaml
The Xcode project I tried to setup using the tutorial above (2° dash) wrapping the OCaml compiler with a git submodule (see .gitmodules file): https://github.com/NathanFallet/OCamlKit
But I'm unable to compile the package I tried to setup to achieve this goal.
Help is welcomed to realize this huge project

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.

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 :)

using c++ files in objective c sample tutorial

Where can I get sample tutorial where I can get how to use visual C++ files in XCODE using objective c? I am working on app which is having multiple visual C++ files. Basically this is an gaming application which is developed for windows. And now want to develop it on iPad. So can I reuse those files?
Thank you in Advance.
You can just add the c++ files directly to Xcode and it will compile them (assuming you have all the proper headers etc). You can create 'bridges' to that code by using ObjectiveC++ - meaning you can set the suffix of an ObjectiveC file to '.mm' and the methods in the file will be visible to any other ObjectiveC object, but you can instantiate C++ objects too. In fact if you have C++ ivars (object variables), they get the proper destruct messages when the ObjectiveC class is released. Google 'ObjectiveC++' for more info.

Use existing DLL in iOS app through mono framework

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.

Resources