Android NDK构建无法构建32位可执行文件 [英] Android ndk build can't build 32bit executable file

查看:112
本文介绍了Android NDK构建无法构建32位可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的第一个问题 ,我尝试在应用程序中包含 fanotify.h 标头。该应用程序基于 fsmon (一个使用fanotify syscall的小型应用程序),我更改了一些代码行为了我的目的,并创建了一个Android.mk生成文件:

Depending on my first question, I tried to include the fanotify.h header in my application. The application is based on fsmon (a small application to use the fanotify syscall), I changed some code lines for my purpose and created an Android.mk makefile:

APP_PLATFORM := android-23
TARGET_PLATFORM := android-23
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# Enable PIE manually. Will get reset on $(CLEAR_VARS). This
# is what enabling PIE translates to behind the scenes.
LOCAL_CFLAGS += -fPIE -DHAVE_FANOTIFY=1 -DHAVE_SYS_FANOTIFY=0 
LOCAL_LDFLAGS += -fPIE -pie

# give module name
LOCAL_MODULE := fsmon

# include fanotify by api 23:
LOCAL_C_INCLUDES := /home/fabian/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/include

# include fanotify by sysroot -> 
# LOCAL_C_INCLUDES := /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/

# list your C files to compile
LOCAL_SRC_FILES := inotify.c fanotify.c util.c main.c

# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)

我需要包含 linux /inotify.h linux / fanotify.h 标头。

执行时 ndk-build ,仅 arm64-v8a mips64 x86_64 可执行文件(在libs / xxx中)由于以下错误消息而被创建:

On executing ndk-build, only the arm64-v8a, mips64 and x86_64 executable files (in libs/xxx) get created cause of following error messages:

fabian@fabian-ubuntu:~/kernel_android_goldfish/fsmon/fsmon/jni$ ndk-build 
[arm64-v8a] Compile        : fsmon <= inotify.c
[arm64-v8a] Compile        : fsmon <= fanotify.c
[arm64-v8a] Compile        : fsmon <= util.c
[arm64-v8a] Compile        : fsmon <= main.c
[arm64-v8a] Executable     : fsmon
[arm64-v8a] Install        : fsmon => libs/arm64-v8a/fsmon
[x86_64] Compile        : fsmon <= inotify.c
[x86_64] Compile        : fsmon <= fanotify.c
[x86_64] Compile        : fsmon <= util.c
[x86_64] Compile        : fsmon <= main.c
[x86_64] Executable     : fsmon
[x86_64] Install        : fsmon => libs/x86_64/fsmon
[mips64] Compile        : fsmon <= inotify.c
[mips64] Compile        : fsmon <= fanotify.c
[mips64] Compile        : fsmon <= util.c
[mips64] Compile        : fsmon <= main.c
[mips64] Executable     : fsmon
[mips64] Install        : fsmon => libs/mips64/fsmon
[armeabi-v7a] Compile thumb  : fsmon <= inotify.c
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
In file included from /home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:82:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:92:21: error: use of undeclared identifier
      '__BITS_PER_LONG'
  unsigned long sig[_NSIG_WORDS];
                    ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:25:38: note: expanded from macro '_NSIG_WORDS'
#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
                                     ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:24:19: note: expanded from macro '_NSIG_BPW'
#define _NSIG_BPW __BITS_PER_LONG
                  ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:94:3: error: typedef redefinition with different
      types ('struct (anonymous struct at /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:91:9)' vs
      'unsigned long')
} sigset_t;
  ^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:20:23: note: previous definition is here
typedef unsigned long sigset_t;
                      ^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:84:8: error: redefinition of 'sigaction'
struct sigaction {
       ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:101:8: note: previous definition is here
struct sigaction {
       ^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:97:16: error: redefinition of
      'sigaltstack'
typedef struct sigaltstack {
               ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:111:16: note: previous definition is here
typedef struct sigaltstack {
               ^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:101:3: error: typedef redefinition with
      different types ('struct (anonymous struct at
      /home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:97:16)' vs 'struct sigaltstack')
} stack_t;
  ^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:116:3: note: previous definition is here
} stack_t;
  ^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:71:9: warning: 'NSIG' macro redefined [-Wmacro-redefined]
#define NSIG _NSIG
        ^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:19:9: note: previous definition is here
#define NSIG 32
        ^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:79:9: warning: 'SIGRTMIN' macro redefined [-Wmacro-redefined]
#define SIGRTMIN (__libc_current_sigrtmin())
        ^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:58:9: note: previous definition is here
#define SIGRTMIN 32
        ^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:80:9: warning: 'SIGRTMAX' macro redefined [-Wmacro-redefined]
#define SIGRTMAX (__libc_current_sigrtmax())
        ^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:59:9: note: previous definition is here
#define SIGRTMAX _NSIG
        ^
5 errors generated.
    make: *** [/home/fabian/kernel_android_goldfish/fsmon/fsmon/obj/local/armeabi-v7a/objs/fsmon/inotify.o] Error 1

inotify.c 的原因,包括 signal.h 标头,其中重新包含 linux / signal.h ,而这又依次包含了 platforms / android-9 / arch-arm / usr /include/asm/signal.h ,出现错误的地方。 (突然来自android-9)。

Cause of inotify.c including the signal.h header which re-includes the linux/signal.h and this in turn the platforms/android-9/arch-arm/usr/include/asm/signal.h , where the error appears. (suddenly from android-9).

我不知道问题出在哪里。.我试图包括sysroot中的include文件夹-但出现类似错误。

I can't figure out where the problem is.. I tried to include the include folder from sysroot - but similar errors appear.

源文件:
inotify.c
fanotify.c

推荐答案

您不应该手动指向中的NDK标头LOCAL_C_INCLUDES 。应该自动添加,指向正确的版本。但是,实际上没有任何东西在这里使用变量 APP_PLATFORM TARGET_PLATFORM

You shouldn't manually point to the NDK headers in LOCAL_C_INCLUDES. This should be added automatically, pointing to the right version. However, nothing actually uses the variables APP_PLATFORM or TARGET_PLATFORM here.

相反,在文件 jni / Application.mk 中添加 APP_PLATFORM:= android-23 。对于所有架构,这应该使它使用正确的平台头进行构建。

Instead, add APP_PLATFORM := android-23 in the file jni/Application.mk. That should make it build using the right platform headers, for all architectures.

这篇关于Android NDK构建无法构建32位可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆