本文介绍了Android.mk,包含所有 cpp 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ndk 构建一个 Android 项目,但遇到了一些麻烦.

I'm trying to build an Android project using the ndk, but I have run into some troubles.

这是有效的 Android.mk 文件:

Here's the Android.mk file that works:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := mylib
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := main.cpp, Screen.cpp, ScreenManager.cpp
LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)

有没有一种方法可以让我指定目录中的所有 *.cpp 文件,而无需在 LOCAL_SRC_FILES 下手动列出它们?

Is there a way that allows me to specify all the *.cpp files in the directory, without listing them manually under LOCAL_SRC_FILES?

到目前为止,我尝试使用 LOCAL_SRC_FILES = $(wildcard *.cpp),但它现在确实有效,似乎没有选择任何文件.

So far I tried using LOCAL_SRC_FILES = $(wildcard *.cpp), but it did now work, it seems that no files get selected.

推荐答案

你可以试试这样的...

You could try something like this...

FILE_LIST := $(wildcard $(LOCAL_PATH)/[DIRECTORY]/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

... 将 [DIRECTORY] 更改为文件的实际目录.如果它们与您的 .mk 文件位于同一目录中,则删除该部分.创建 FILE_LIST 变量以查找 [DIRECTORY] 目录下的所有 .cpp 文件.然后在文件列表中使用它.然后,LOCAL_SRC_FILES 行将从列表中删除 LOCAL_PATH.

... Change [DIRECTORY] to the actual directory of the files. If they are in the same directory as your .mk file then remove that part. Create the FILE_LIST variable to find all of the .cpp files under the [DIRECTORY] directory. Then use it in the file listing. The LOCAL_SRC_FILES line will then remove the LOCAL_PATH from the listing.

这篇关于Android.mk,包含所有 cpp 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 12:45