Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C++ code (Xcode) for iOS and Android. Is it real? [closed]

I wanna try to write and compile C++ code for iOS and Android-devices. I've been using Xcode for some time (I was writing c++ code for MacOS and Windows). So I wanna use Xcode for my purposes.

The problem is that I don't know how to compile C++ code both for Android devices and for iPad/IPhone. I wanna use crossplatform-solution for iOS and Android but don't want to use such frameworks as Marmalade (c++) or others.

Is it real or not? :) Is there tutorials or other helpful materials?

like image 657
JavaRunner Avatar asked Mar 04 '13 21:03

JavaRunner


People also ask

What C compiler does XCode use?

Xcode uses two different compilers: one for Swift and the other for Objective-C, Objective-C++ and C/C++ files. clang is Apple's official compiler for the C languages family. It is open-sourced here: swift-clang. swiftc is a Swift compiler executable which is used by Xcode to compile and run Swift source code.

Does C++ run on iOS?

It installs the SDKs and tools you need for cross-platform development of shared libraries and native apps. When it's installed, you can use C++ to create code that runs on iOS and Android devices and platforms, Windows, Windows Store, and Xbox.

Can you build iOS apps with C++?

Short answer, yes, sort of. You can use Objective-C++, which you can read about at Apple Developer Connection. If you know C++ already, learning Objective-C would be pretty simple, if you decided to give that a try.

How do I compile and run XCode?

To compile and run your program, click the run button in the top left corner of the window. When your program runs, XCode will open an output pane. You can see any output that your program generated in that pane.


1 Answers

You can most definitely use C++ on iOS and Android. I have written my own game engines for both.

Xcode is the normal IDE for iOS and natively supports "Objective-C++" development (The compiler supports both Objective-C and C++). You will need to write a thin wrapper in Objective-C to interact with the OS, but you can write everything else in C++ if you like. If you download the Xcode command line tools you can also build from scripts.

Eclipse is the usual IDE for Android and if you download the NDK you can utilize JNI to interface between Java and C++. Much like iOS you will at least require a Java wrapper to interact with the OS.

You are not limited to Eclipse and Xcode, however. You could for example use emacs and/or employ CMake to allow you to try and consolidate the project settings a bit. Emacs is a very powerful and flexible IDE, but it has a very steep learning curve and not very straight forward to install. If you do this on Mac I would recommend emacsformacosx and installing ECB and autocomplete as well. CMake is basically a cross platform build system that allows you to build many different project files (Visual Studio, Xcode, Eclipse, etc.) from one source tree. Much like emacs this is super powerful yet somewhat of a steep learning curve. If you want to jump in right away you will likely want to start off with both Xcode and Eclipse. If you are developing on a PC you would require a Mac VM or a Hackintosh to use Xcode and cygwin to use the NDK for android (Macbook Pro users can have fun right away with little hassle).

Native Android development is definitely much more difficult. Not only do you have much more device segmentation to contend with, but native debugging is not very straight forward. You must run a GDB server on the device and connect with it to set breakpoints and many people do this from the command line. I have heard some people have success with the Tegra Tools for Eclipse if you want a GUI based IDE.

I would definitely recommend developing on iOS first as you have way more powerful tools at your disposal from the IDE. You can track memory leaks, profile code, set break points easily ;), etc. Once you develop a feature on the iOS you can then wrestle with the .mk files and other goodness of Android native development.

Here is some information on the core objects and life cycle for iOS:

  • Core Objects
  • Lifecycle

and for Android:

  • Lifecycle

As long as you play nice with the OS and respect the lifecycle of the application you are free to make calls to C++ logic. You can do this directly with iOS, but with Android you have to marshall the calls through JNI. If you encapsulate the platform specifics you can share the C++ logic between both platforms.

I'm a huge advocate of C++, but the choice to use it does depend on the situation for these platforms. C++ is not the popular choice for these platforms and as such you will not find as much documentation (your on your own much of the time). The complexity can go up a bit if you are not very familiar with C++ (Are you familiar with RAII, design patters, STL?).

Here are a few situations where it may make sense:

  • If you need to utilize a library that was authored in C/C++
  • If you would like to build your own platform agnostic framework for your apps or games
  • If you are working with realtime / performance critical applications such as games

I'm not saying you MUST use C++ in these situations as many people have developed games in Objective-C. I'm just saying it may be something to consider if you need to get the most out of the hardware or you simply want something more portable.

like image 148
Matthew Sanders Avatar answered Sep 22 '22 09:09

Matthew Sanders