2017-03-31 176 views
0

根據我的第一個question,我試圖在我的應用程序中包括fanotify.h標題。該應用程序是基於fsmon(一個小應用程序使用系統調用fanotify),我改變了一些代碼行我的目的,並創建了一個Android.mk生成文件:Android ndk內置不能建立32位可執行文件

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.hlinux/fanotify.h頭。

上執行ndk-build,只有arm64-v8amips64x86_64可執行文件(在庫/ XXX)獲得創建以下錯誤消息的原因:

原因 inotify.c包括 signal.h報頭
[email protected]:~/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 

重新包括linux/signal.h,而這又出現錯誤platforms/android-9/arch-arm/usr/include/asm/signal.h。 (突然從android-9)。

我找不出問題出在哪裏..我嘗試從sysroot包含include文件夾 - 但出現類似的錯誤。

源文件: inotify.c fanotify.c

回答

3

則不應手動指向NDK頭在LOCAL_C_INCLUDES。這應該會自動添加,指向正確的版本。但是,這裏並沒有使用變量APP_PLATFORMTARGET_PLATFORM

取而代之,在文件jni/Application.mk中添加APP_PLATFORM := android-23。對於所有體系結構,這應該使用正確的平臺標題進行構建。

+0

哇,非常感謝!是的,這是問題...這個簡單的行在Application.mk中是必需的。現在它工作了! – Fabman22

1

除了@ mstorsjo的回答,您可以在NDK r14及更新版本中使用Unified Headers。這些是標題的一種新形式,始終保持最新狀態,而不是爲每個API級別設置不同的標題集。

的這種過度增加你APP_PLATFORM的好處是,你的APP_PLAFORM不能高於你的minSdkVersion(查看我們的common problems doc)。由於fanotify是在相當老版本的內核中引入的(2.6.36代表fanotify_init),即使該函數在舊版本的libc中不存在,您仍然可以使用syscall(__NR_fanotify_init)對其進行調用。儘管如此,ENOSYS始終是一種可能性。

默認情況下,在r14中,您仍然可以看到舊的標題形式。新的「統一標題」有你正在尋找的標題。如果您想嘗試統一標題,請在您的Application.mk中設置APP_UNIFIED_HEADERS := true(其他構建系統的設置可以在上面的鏈接中找到)。

在r15(即將推出的第一個測試版)中,默認已更改爲新標題,並且禁用它們的選項已更改(請參閱same doc in r15)。

+0

確實!這也是一種可能(或更好)的方式來做到這兩件作品 - 謝謝! – Fabman22

相關問題