如何使用mkfifo子采用Android的NDK如何使用、mkfifo、NDK、Android

2023-09-13 01:14:37 作者:她它他,去死吧。

最近我升级了NDK,现在我的应用程序崩溃,丢失符号 mkfifo子

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"...

mkfifo子定义内联 SYS / stat.h

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

但平台版本的21年又改为只需一个外部decleration:

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?

推荐答案

这会发生,如果你建立对的android-21 平台头。设置 APP_PLATFORM JNI / Application.mk 来的旧版本,生成使用旧的头,以确保您只能链接到可用功能更早。

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.

(前的android-21 ,C库功能和头并没有真正显著改变,所以对于普通的C库函数,它并不重要,如果你无所谓建立针对的android-3 的android-20

(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.)

这已经报告,并故意行为,如见https://$c$c.google.com/p/android/issues/detail?id=73725.

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

如果您不需要使用新功能,从的android-21 ,只是建立使用旧头。 (没关系,你瞄准一个旧的平台版本,如果你想尝试搭建例如 arm64-V8A x86_64的之前并不存在; NDK建造将建立32位的部分用旧的目标,并使用最古老的目标,支持64位的人它们。)

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.)

如果你想尝试有条件,如果在这样的平台上运行使用新功能,从的android-21 的平台,你可能需要使用执行dlopen 则dlsym 加载它有条件无论如何,这样的话,你需要复制的新报头中的其他定义为好,让你建立一个使用旧的平台头。

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.