Android的NDK - 附加包含目录 [英] Android NDK - Additional Include Directories

查看:550
本文介绍了Android的NDK - 附加包含目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了Android NDK构建一个共享库。我有包括我的Andr​​oid.mk文件引起了我几个问题,一个片段。

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)

我spatialite.c文件包括位于该外部应用程序项目文件夹的文件夹中一些头文件。我已经包括在LOCAL_C_INCLUDES该文件夹如上图所示,但在运行NDK的构建,它仍然无法找到这些包括。是什么让NDK-build命令来标识这些包括所在的正确途径。任何帮助将大大AP preaciated。

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.

更新:

我想补充一点,spatialite本身不必是可见的Java层。我此后将被建立,它使用spatialite另一个模块。我不知道这使得以我宣布在Android.mk文件中模块的方式不同。

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.

编译器输出如下所示:
JNI / spatialite.c:102:20:​​致命错误:geos_c.h:没有这样的文件或目录
 的#include

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

这是spatialite.c导入.h文件位于C:/项目/ externalappsdk /包括。该spatialite.c和Android.mk位于C:/移动/ myandroidproject / JNI /

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/

在包括我spatialite.c文件中的指令如下所示:

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

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

解答:
我设法得到这种帮助,使用从我已经接受了克里斯提供的答案工作。但是,我不得不做出一个改变的Andr​​oid.mk文件如下:

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)

请注意,该LOCAL_C_INCLUDES去两级背而不是三个。

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

推荐答案

如果没有

LOCAL_PATH := $(call my-dir)

在Android.mk的顶部,我无法描述构建项目的翻版,但误差比您的报告不同 - 没有该指令编译器在一个NDK系统搜索的C源文件目录,而在JNI /文件夹。

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

文件:./mobile/myandroidproject/jni/Android.mk

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)

文件:./mobile/myandroidproject/jni/spatialite.c

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

#include <geos_c.h>

文件:./mobile/myandroidproject/jni/sqlite3.c

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

//empty file

文件:./projects/externalappsdk/include/geos_c.h

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

//empty file


您至少应该在LOCAL_PATH行添加到您的Andr​​oid.mk


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.

这篇关于Android的NDK - 附加包含目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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