0

I'm trying to compile a C program for Android 6. This is my Android.mk:

APP_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
# 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)

In the fanotify.c following include is written:

#include <linux/fanotify.h>

When I try to use ndk-build, following error appears:

fsmon/jni/fanotify.c:51:10: fatal error: 'linux/fanotify.h' file not found
#include <linux/fanotify.h>
         ^

The header fanotify.h is present in the ndk path /Android/Sdk/ndk-bundle/sysroot/usr/include/linux

Any suggestions?

EDIT: Same error if I try to include sys/fanotify.h

Fabman22
  • 183
  • 12
  • Hmm okay it's not present in `ndk-bundle/platforms/android-23/arch-arm/usr/include/linux` ... how can I tell it to use it from sysroot/ ? – Fabman22 Mar 30 '17 at 17:37

2 Answers2

0

You can specify additional include paths for your module using LOCAL_C_INCLUDES.

LOCAL_C_INCLUDES := /Android/Sdk/ndk-bundle/sysroot/usr/include/

https://developer.android.com/ndk/guides/android_mk.html#mdv

iVoid
  • 701
  • 3
  • 14
  • Okay thanks, this works. But now I get 5 errors: `/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 /Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:97:16)' vs 'struct sigaltstack') } stack_t;` Then I included api 23, but then 3 errors appear: `Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/include/signal.h:87:12: error: duplicate member '_u'` do you have an idea? ` – Fabman22 Mar 30 '17 at 23:13
  • I think your design is probably not right - either you're including different versions of the same include files or you're including different include files which have the same definitions. But I guess, from the state you've now progressed to, you should probably try to debug the errors one-by-one by removing header file duplication or definition duplication. – iVoid Mar 31 '17 at 04:14
  • Hm yes it's strange, because the 64bit executable files get created.. It's only a problem with the 32bit versions. It's also strange how the header files get link from sysroot to the android-9 api. I tried now a lot of variations, but no success... Maybe I will create another question for this problem, the other one with the non finding library was solved. – Fabman22 Mar 31 '17 at 11:25
  • So here if you can figure out something... but thanks for the other answer! http://stackoverflow.com/questions/43140359/android-ndk-build-cant-build-32bit-executable-file – Fabman22 Mar 31 '17 at 12:27
  • Sure, I'll go through the question and try to help if I can! – iVoid Mar 31 '17 at 12:32
  • You should not do this. You're mixing and matching the old headers and the new headers. It's not a tested configuration and as you can see that leads to other issues, since you're now actually mixing some very up to date headers with some very out of date headers. See my answer for the correct way to get the up to date headers. – Dan Albert Mar 31 '17 at 20:27
0

The NDK historically didn't backport headers to old releases, but we've reworked things in r14 so this is possible: https://android.googlesource.com/platform/ndk/+/ndk-r14-release/docs/UnifiedHeaders.md

By default in r14 you still get the old form of the headers. The new "unified headers" have the headers you're looking for. If you want to try unified headers, set APP_UNIFIED_HEADERS := true in your Application.mk (settings for other build systems can be found in the link above).

In r15 (first beta due out soon), the default has changed to the new headers, and the option for disabling them has changed (see the same doc in r15 for changes in options: https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md).

Dan Albert
  • 10,079
  • 2
  • 36
  • 79