Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine C code is compiled for Android/NDK or iOS

I am reusing a legacy C library in an iOS app and in an Android app. I want to customize some macro definitions (e.g. for logging). Are there standard defines to check for (using #ifdef) whether the code is being compiled for iOS or Android/NDK?

like image 641
Miriam Avatar asked Dec 03 '10 12:12

Miriam


People also ask

Does Android use GCC?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.

How does an Android APK execute compiled native code?

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE's integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.

How do I open a .C file on Android?

To Install and Use C/C++ compiler in Termux (in Termux clang is the C/C++ compiler) , Download & Install Termux from : Play Store. After Installing execute this command pkg install clang. After Successfully installing clang you can compile C/C++ scripts.

Where is libc ++_ shared so?

Note: libc++ is not a system library. If you use libc++_shared.so , it must be included in your app. If you're building your application with Gradle this is handled automatically. The LLVM Project is under the Apache License v2.


2 Answers

__ANDROID__ or ANDROID for Android (compilation with the NDK) and __APPLE__ on Apple platforms (iOS or OSX)

like image 115
Stéphane Avatar answered Oct 11 '22 17:10

Stéphane


you should consider creating two separate projects for those platforms with separate output/bin directories but shared source code. Then you just set some define in project properties for android and ios so you can recognize it when compiling

like image 43
fazo Avatar answered Oct 11 '22 15:10

fazo