Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use mkfifo using Android's NDK

Recently I upgraded the NDK and now my app crashes with missing symbol mkfifo:

E/dalvikvm(2031): dlopen("/data/app-lib/...mylib.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "mkfifo" referenced by "mylib.so"...

The older platforms mkfifo was defined inline in sys/stat.h

static __inline__ int mkfifo(const char *__p, mode_t __m) {
    return mknod(__p, (__m & ~S_IFMT) | S_IFIFO, (dev_t)0);
}

But in platform version 21 it was changed to just an extern decleration:

extern int mkfifo(const char*, mode_t);

So that explains the missing symbol exception... my question is how do I fix it?

like image 406
Iftah Avatar asked Nov 23 '14 16:11

Iftah


1 Answers

This happens if you build against the android-21 platform headers. Set APP_PLATFORM in jni/Application.mk to an older version, to build using the old headers, to make sure you only link to functions available earlier.

(Before android-21, the C library features and headers didn't really change significantly, so for the normal C library functions, it doesn't matter if you build targeting android-3 or android-20.)

This has been reported and is intentional behavior, see e.g. https://code.google.com/p/android/issues/detail?id=73725.

If you don't need to use new features from android-21, just build using older headers. (It doesn't matter that you're targeting an older platform version if you want to try to build for e.g. arm64-v8a or x86_64 that didn't exist before; ndk-build would build the 32 bit parts using the older target, and the 64 bit ones using the oldest target that supports them.)

In case you want to try to use new features from the android-21 platform conditionally if running on such a platform, you probably need to use dlopen and dlsym to load it conditionally anyway, so then you need to duplicate the other definitions from the new headers as well, to allow you to build using the older platform headers.

like image 172
mstorsjo Avatar answered Oct 12 '22 10:10

mstorsjo