Is Android POSIX-compatible?

Android is not fully POSIX compatible. First what I can notice is default c library. As you may know it is called glibc. But Android has its own c library - bionic. Here are some notes.

Some functions within Bionic's POSIX and system call headers are stubs or wrappers for Android-specific behavior, causing unintended behavior in some instances.

Android uses linux-based kernel, so you can say that it is POSIX compliant. But in general Android doesn't comply with Unix specifications such as POSIX either. Also you can read something like that

Bionic does not include C++ exception handling, perhaps as Google does not use C++ exceptions and Java exceptions are available once the Java virtual machine is started

Bionic does not include the Standard Template Library, and developers must include it manually if they need it

There is great custom build NDK - CrystaX NDK

Key features of the CrystaX NDK:

Wide characters. Google's NDK doesn't support wide chars properly in C or C++. With the CrystaX NDK, you get full standard compliant wide characters support. You can easily port existing code that uses wide characters/strings/streams or write new code.

The most recent toolchains The CrystaX NDK includes the most recent versions of GCC and Clang compilers as well as stables. This allows developers to use new language abilities (such as new C++ 11 features). All compilers are built with high- and low-level optimizations which enables generation of the most efficient code for target hardware.

C++11 support Since the CrystaX NDK includes the most recent versions of GCC and Clang, it supports many new C++ 11 features listed on C++0x/C++11 Support in GCC and C++98 and C++11 Support in Clang. In addition, the CrystaX NDK offers fully working C++ 11 classes std::thread, std::mutex, std::chrono etc. These classes are not available in the Google NDK because of lack of functionality in Android Bionic libc. We have investigated this problem and fixed it, so in the CrystaX NDK you can just use them and forget about ifdefs.

Objective-C support The only languages the Google NDK supports are C and C++. The CrystaX NDK adds support of Objective-C in addition to C and C++. Only the core language is supported as of now; work on Cocoa-like libraries is in progress. To start using Objective-C in your project, just add source files with the extension .m (Objective-C) or .mm (Objective-C++) and specify them in LOCAL_SRC_FILES in Android.mk.

To be continued... If you don't see some great feature here, don't hesitate to contact us and ask for it. You can also use our issue/bug tracker to report bugs or feature requests. And, of course, contributions are welcome!

You can find more information on Official CrystaX NDK site


GNU libc (glibc) is too big and complicated for mobile phones, so Android implements its own special version of libc which is Bionic libc, which itself does not fully support POSIX. One of the most lacking features in the android Bionic libc is pthread_cancel(), so if you don't use it, your code will probably do fine.

And also as @code monkey mentioned you can take a look to the bionic source code. You can find additional information here .

Tags:

C

Android

Posix