Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何告诉Android NDK使用不同的工具链_Android_Android Ndk_Toolchain - Fatal编程技术网

如何告诉Android NDK使用不同的工具链

如何告诉Android NDK使用不同的工具链,android,android-ndk,toolchain,Android,Android Ndk,Toolchain,我下载了一个定制的工具链()来构建基于ARM的Android应用程序。我如何告诉NDK使用它?我可以在Android.mk和Application.mk中定义或设置一些允许我这样做的东西吗?还有其他方法吗?NDK makefile系统非常可扩展,您确实可以定义不同的工具链。你需要了解Make是如何工作的 工具链在build/core/init.mk第261行中发现并初始化(在NDKr6中,该行在未来版本中可能会更改)。初始化代码在$(NDK_ROOT)/toolschains/*下查找名为con

我下载了一个定制的工具链()来构建基于ARM的Android应用程序。我如何告诉NDK使用它?我可以在Android.mk和Application.mk中定义或设置一些允许我这样做的东西吗?还有其他方法吗?

NDK makefile系统非常可扩展,您确实可以定义不同的工具链。你需要了解Make是如何工作的

工具链在
build/core/init.mk
第261行中发现并初始化(在NDKr6中,该行在未来版本中可能会更改)。初始化代码在
$(NDK_ROOT)/toolschains/*
下查找名为
config.mk
的文件。因此,您需要将工具链添加到NDK toolchains目录下的子目录中,并将
config.mk
setup.mk
添加到该子目录中。查看
toolschains/x86-4.4.3
toolschains/arm-linux-androideabi-4.4.3
以获取示例。如果您的工具链具有标准布局,则应该能够剪切和粘贴ARM工具链
config.mk
setup.mk


一旦在toolchain目录中定义了工具链,就可以通过在
应用程序.mk
文件中设置
NDK\U toolchain
变量来切换到它。

正如其他答案所提到的,工具链是由NDK build makefile system在
$(NDK\U根目录)中发现的/工具链/
,您可以镜像您在那里看到的想法。但是,对于支持非Android目标平台,还有一些额外的概念很有趣,尽管随着ndk build开始明确支持其他平台,例如针对win32的mingw(或其他针对纯“ol linux”的gcc编译器),这些概念可能很快就过时了

config.mk
中:

TOOLCHAIN_ABIS := (list of ABIs that the toolchain supports)
# These flags are used to enforce the NX (no execute) security feature in the
# generated machine code. This adds a special section to the generated shared
# libraries that instruct the Linux kernel to disable code execution from
# the stack and the heap.
TARGET_NO_EXECUTE_CFLAGS  := # our platform doesn't support this flag!
TARGET_NO_EXECUTE_LDFLAGS := # our platform doesn't support this flag!

# These flags disable the above security feature
TARGET_DISABLE_NO_EXECUTE_CFLAGS  :=  # our platform doesn't support this flag!
TARGET_DISABLE_NO_EXECUTE_LDFLAGS :=  # our platform doesn't support this flag!
这是一个重要的定义,因为您可以在Application.mk中使用此名称来使用特定ABI的工具链进行构建。破坏此定义的使用的好处之一是ndk build可以同时为多个ABI构建。它总是假设平台是Android,但如果您想使用基于mingw的工具链以win32为目标,可以将“ABI”定义为
x86-win32
,然后在您的
应用程序.mk
中使用此ABI,通过
APP\u ABI:=x86-win32
选择它作为附加目标,然后在您的
Android.mk
文件中,您可以使用
target\u ARCH\u ABI
定义来选择win32特定源并包括路径,例如:

ifeq ($(TARGET_ARCH_ABI),x86-win32)
  LOCAL_SRC_FILES += my_win32_file.c
  LOCAL_CFLAGS += -DSOME_WIN32_SPECIFIC
endif
最后一点是,在工具链的
setup.mk
中,仅以其他工具链为例是不够的,因为特定工具链的
setup.mk
真正做的是覆盖
默认构建命令.mk
中的构建设置,所以您要做的是检查该文件,重新定义你不喜欢的东西

按照前面的示例,mingw不支持二进制文件中的noexec标志,您可以通过在
setup.mk
中添加以下行来摆脱此功能:

TOOLCHAIN_ABIS := (list of ABIs that the toolchain supports)
# These flags are used to enforce the NX (no execute) security feature in the
# generated machine code. This adds a special section to the generated shared
# libraries that instruct the Linux kernel to disable code execution from
# the stack and the heap.
TARGET_NO_EXECUTE_CFLAGS  := # our platform doesn't support this flag!
TARGET_NO_EXECUTE_LDFLAGS := # our platform doesn't support this flag!

# These flags disable the above security feature
TARGET_DISABLE_NO_EXECUTE_CFLAGS  :=  # our platform doesn't support this flag!
TARGET_DISABLE_NO_EXECUTE_LDFLAGS :=  # our platform doesn't support this flag!

这只是
default build commands.mk
中可能需要覆盖的许多功能的一个示例,当然,提供
TOOLCHAIN\u NAME
非常重要,这样就可以通过
应用程序.mk
文件中的
NDK\u TOOLCHAIN
变量来选择工具链。除了我上面提到的ABI方法之外。

您可以简单地添加“NDK\u TOOLCHAIN\u VERSION=4.9”在你的应用程序.mk中,你是在Ubuntu上这样做的吗?你是如何安装工具链的?