Android NDK - Additional Include Directories

放肆的年华 提交于 2019-12-11 02:52:45

问题


I am using the Android NDK to build a shared library. I have include a snippet from my Android.mk file that is causing me a few issues.

LOCAL_PATH := $(call my-dir)

..#other module here
..#other module here

include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

My spatialite.c file includes some header files that are located in a folder that is external to the application project folder. I have included that folder in LOCAL_C_INCLUDES as shown above, but on running ndk-build, it still cannot locate these includes. What is the correct way of allowing the ndk-build command to identify where these includes are located. Any help will be greatly appreaciated.

UPDATE:

I wanted to add that spatialite itself need not be visible to the Java layer. I will thereafter be building another module which uses spatialite. I am not sure if this makes a difference to the way I declare the module on the Android.mk file.

The compiler output is shown below: jni/spatialite.c:102:20: fatal error: geos_c.h: No such file or directory #include

The .h file that is being imported in spatialite.c is located at C:/projects/externalappsdk/include. The spatialite.c and Android.mk are located at C:/mobile/myandroidproject/jni/

The include directive within my spatialite.c file is shown below:

#ifndef OMIT_GEOS   /* including GEOS */
#include <geos_c.h>
#endif

ANSWER: I managed to get this working using help from the answers provided by Chris which I have accepted. However, I had to make one change to the Android.mk file as is shown below:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

Note, that the LOCAL_C_INCLUDES goes two levels back instead of three.


回答1:


Without a

LOCAL_PATH := $(call my-dir)

At the top of the Android.mk, I was unable to build a replica of your project as described, however the error was different than your report - without that directive the compiler was searching for the C source files in an NDK system directory rather in the jni/ folder.

$ cd mobile/myandroidproject/jni
$ ndk-build
Compile thumb  : spatialite <= spatialite.c
SharedLibrary  : libspatialite.so
Install        : libspatialite.so => libs/armeabi/libspatialite.so

File: ./mobile/myandroidproject/jni/Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

File: ./mobile/myandroidproject/jni/spatialite.c

#include <geos_c.h>

File: ./mobile/myandroidproject/jni/sqlite3.c

//empty file

File: ./projects/externalappsdk/include/geos_c.h

//empty file

At minimum you should add the LOCAL_PATH line to your Android.mk

If that does not solve the problem, then please update your question with any differences between your project structure and my recreation of it.




回答2:


Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES



来源:https://stackoverflow.com/questions/22483595/android-ndk-additional-include-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!