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?
Asked
Active
Viewed 3,529 times
10
-
3Please don't use `#ifdef` for this. Write portable code and put platform-specific issues in per-platform modules with a common interface. – Fred Foo Dec 03 '10 at 13:17
-
Put in the different module, compile each using different include path – qrtt1 Dec 03 '10 at 14:25
-
3Generally, but one must balance the magnitude of the difference with the desirability of keeping functionality organized. Over use of abstraction can just as easily make code unreadable as under use. If I had a large block of code that was identical except for one inherited linux-vs-bsd difference in a unix system call, I'd probably #ifdef it with a comment right there, rather than invent a new personal concept of portable unix and bury the implementation in inline functions pulled from some header file. – Chris Stratton Dec 03 '10 at 16:02
2 Answers
23
__ANDROID__
or ANDROID
for Android (compilation with the NDK)
and __APPLE__
on Apple platforms (iOS or OSX)

Stéphane
- 6,920
- 2
- 43
- 53
-
-
6No, it is `__ANDROID__` **with** underscores. Quoting [David Turner](http://markmail.org/message/5ekhfztchs45lz3n): “I would recommend defining `__ANDROID__` explicitely for now, it should be the only thing that NDK users should be testing again”. – sam hocevar Sep 18 '11 at 20:21
1
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

fazo
- 1,807
- 12
- 15