本文介绍了如何编译使用Android NDK静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想编译静态库在Android上使用,但我想不出如何编译它。库使用标准库(stdio.h中等等)和libxml2的。

I'm trying to compile a static library to use on Android but I can't figure out how to compile it. The library uses standard libraries (stdio.h etc...) and libxml2.

我试图用手臂EABI-GCC编译器,但我得到了以下错误:

I am trying to compile using arm-eabi-gcc but I get the following error:

/cygdrive/c/android-ndk-r4/build/platforms/android-8/arch-x86/usr/include/asm/posix_types.h:15:28:错误:posix_types_64.h:没有这样的文件或目录

/cygdrive/c/android-ndk-r4/build/platforms/android-8/arch-x86/usr/include/asm/posix_types.h:15:28: error: posix_types_64.h: No such file or directory

我如何得到这个工作?

推荐答案

据我了解,正确的方法是使用 NDK建造并没有直接调用编译器。

As I understand it, the correct method is to use ndk-build and not invoking the compiler directly.

Android.mk 您需要指定要编译每个静态库中的模块,然后指定你的共享库应该使用它。

In Android.mk you need to specify a module for each static library you want to compile, and then specify that your shared library should use it.

在HELLO-JNI样本项目的修改Android.mk文件的例子:

Example of a modified Android.mk file of the hello-jni sample project:

LOCAL_PATH := $(call my-dir)

# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES :=  <list_of_src_files>

# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g

include $(BUILD_STATIC_LIBRARY)

# First lib, which will be built statically.
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_STATIC_LIBRARIES := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES := hello-jni.c

include $(BUILD_SHARED_LIBRARY)

如果你想控制的模块在运行NDK建造可以创建创建一个 Application.mk 文件(在同一目录Android.mk),并列出所有模块的编译在下面的示例:

If you want control over which modules to compile when you run ndk-build you can create create a Application.mk file (in the same directory as Android.mk) and list all the modules as in the following example:

APP_MODULES := <module_name_1> <module_name_2> ... <module_name_n>

这篇关于如何编译使用Android NDK静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:29