Android.mk相对路径还是绝对路径?

8

我正在尝试使用Android NDK(在Windows上)构建项目,但我遇到了一些问题,特别是源文件(Android.mk中的LOCAL_SRC_FILES

我正在尝试使用相对路径到父文件夹,例如

LOCAL_SRC_FILES := ../../../src/main.cpp

运行ndk_build.cmd时,它输出以下错误:

Compile++ thumb : GTP <= main.cpp
The system cannot find the file specified.
make: *** [obj/local/armeabi/objs/GTP/__/__/__/src/.o] Error 1

所以我尝试使用绝对路径:

LOCAL_SRC_FILES := D:/Path/To/src/main.cpp

很遗憾,这不起作用,因为 : 在 Windows 上会出现问题

有没有办法可以指定相对目录(或绝对目录)中的源文件?我之所以问是因为如果可能的话,我想避免创建到 src 文件夹的符号链接。

3个回答

11

根据ndk文档,建议使用相对路径和以下宏(Android.mk使用make文件的语法):

根据 ndk 文档建议使用相对路径以及以下宏(Android.mk 使用 make 文件的语法):

  LOCAL_PATH := $(call my-dir)

An Android.mk file must begin with the definition of the LOCAL_PATH variable.
It is used to locate source files in the development tree. In this example,
the macro function 'my-dir', provided by the build system, is used to return
the path of the current directory (i.e. the directory containing the
Android.mk file itself).

那么你可以将你的LOCAL_SRC_FILES替换为类似以下内容的东西:

LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../src/main.cpp

1
在处理分布在许多目录中的源文件时,最简单的方法是为每个目录或一组目录编译单独的静态库。在NDK中,这些库称为“模块”。对于每个模块,您需要在Android.mk中指定LOCAL_SRC_PATH。LOCAL_SRC_FILES相对于此路径。但请注意,LOCAL_C_INCLUDES等与项目根目录(通常是jni目录上面的那个目录)相关联。
您可以在项目中拥有许多Android.mk文件,但是您可以使用单个Android.mk构建许多模块。

0

试试这个:

LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := YOUR_SRC_IN_LIB_JNI

1
你的 YOUR_SRC_IN_LIB_JNI 是什么? - IgorGanapolsky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接