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

问题描述

我正在使用 Android NDK 构建我的 cocos2dx 项目,在 Android.mk 中,有一个 LOCAL_SRC_FILES 的定义,其中列出了每个 cpp 文件.每当我添加一个新的源文件时,我也需要在那里添加它......它看起来像这样:

I am using Android NDK to build my cocos2dx project, within the Android.mk, there is a definition for LOCAL_SRC_FILES where each of the cpp file are listed. Whenever I added a new source file, I'd need to add it there as well... it looks like this:

LOCAL_SRC_FILES := hellocpp/main.cpp
                   hellocpp/myclass.cpp
                   hellocpp/mynextclass.cpp
                   ../../Classes/Screens/LaunchScreen.cpp

但是,头文件可以指定要包含的整个目录,如下所示:

the header file, however, can specify the entire directory to include, it looks like this:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/hellocpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/Screens

我已经尝试了各种方法来包含整个目录而不是 LOCAL_SRC_FILES 的单个文件,这样我就不需要在添加新文件时修改 Android.mk 构建脚本,但是,到目前为止我所有的尝试都失败了.

I have tried various ways to include the whole directory instead of single file for the LOCAL_SRC_FILES so that I don't need to modify the Android.mk build script whenever I add a new file, however, so far all my attempts failed.

我试过这个:

#SRC_PATH_HELLOCPP := $(wildcard hellocpp/*.cpp)
#SRC_PATH_CLASSES += $(wildcard ../../Classes/*.cpp)

#LOCAL_SRC_FILES := $(SRC_PATH_HELLOCPP:$(LOCAL_PATH/%=%)
#LOCAL_SRC_FILES += $(SRC_PATH_CLASSES:$(LOCAL_PATH/%=%)

还有这个:

#LOCAL_SRC_FILES += hellocpp/*.cpp
#LOCAL_SRC_FILES += ../../Classes/*.cpp

两者都不工作...

虽然我有另一个项目与第一个选项配合得很好,但我真的不明白为什么它在 cocos2dx 项目中不起作用......有人知道为什么或知道解决方案吗?或者也许我应该让它保持原样并承担麻烦,因为每个人都在这样做.但这真的很麻烦,希望有人能提供帮助,以便我们所有人都能更有效率...

I have another project that works well with the first option though, I really do not understand why it doesn't work in the cocos2dx project... does anybody know why or know the solution? Or maybe I should just leave it as is and take the trouble, since everybody is doing that., but it is really troublesome, hope somebody can help so that all of us can be more productive..

谢谢!

推荐答案

通配符也适用于 cocos2dx 项目.我自己用的,只是你的语法不正确

The wildcard works for cocos2dx projects as well. I am using it on my own, just that your syntax is incorrect

试试:

HELLOCPP_FILES  := $(wildcard $(LOCAL_PATH)/hellocpp/*.cpp)
HELLOCPP_FILES  := $(HELLOCPP_FILES:$(LOCAL_PATH)/%=%)

CLASSES_FILES   := $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
CLASSES_FILES   := $(CLASSES_FILES:$(LOCAL_PATH)/%=%)

LOCAL_SRC_FILES := $(HELLOCPP_FILES)
LOCAL_SRC_FILES += $(CLASSES_FILES)

这篇关于Android.mk - 在一个目录中构建所有源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 04:56