使用 Android NDK 包含库文件
我正在使用一个大型文件库,并且有一个 .cpp 需要编译。我的所有 #include 语句(已编写的 .cpp 和 .h“库”文件)都位于与要编译的 .cpp 不同的文件夹(加上子文件夹)中。
我已经为我的程序中的 Java 文件编写了一个 Eclipse 项目,并使用 CDT 插件来处理我的 C++ 文件和编译,但经过一番调查后,我似乎最终需要使用 ndk-build,所以我执行了以下操作。
我正在编写 Android.mk 文件,但不确定如何构建它。到目前为止我已经掌握了基础知识:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloAndroid
LOCAL_SRC_FILES := HelloAndroid.cpp
include $(BUILD_SHARED_LIBRARY)
但是,当然,当我运行 ndk-build 时,对于 HelloAndroid.cpp 中的每个 #include 语句,我都会收到 No such file or directory
错误,因为我没有指定位置这些文件是。
我该怎么做?有没有办法包含整个目录,就像 g++ 中的 -I 一样?或者我是否以某种方式将这些文件添加到 LOCAL_SRC_FILES 中,或者指定更多模块?我还将这些文件编译为 .a 文件。我可以以某种方式将它们添加为库文件吗?
I'm working with a large library of files, and have one .cpp to compile. All of my #include statements (.cpp and .h "library" files that are already written) are in a different folder (plus subfolders) than the .cpp to compile.
I've put together an Eclipse project for the Java files in my program, and am using the CDT plugin for my C++ files and compilation, but after some investigating it seems I needed to use ndk-build after all, so I did the following.
I'm writing my Android.mk file, and am not sure how to structure it. I have the basics so far:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := HelloAndroid
LOCAL_SRC_FILES := HelloAndroid.cpp
include $(BUILD_SHARED_LIBRARY)
But of course I get a No such file or directory
error when I run ndk-build, for every #include statement in HelloAndroid.cpp, since I haven't specified where those files are.
How would I do this? Is there some way to include an entire directory, like -I in g++? Or do I add these many files to LOCAL_SRC_FILES
somehow, or specify more modules? I also have these files compiled somewhere as .a files. Could I add them as library files somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实应该阅读 NDK 的 docs 目录中的 ANDROID-MK.html 文件。简而言之,您可以包含(使用 LOCAL_C_INCLUDES)和编译器标志(使用 LOCAL_CFLAGS),并且它们会像平常一样传递给编译器。您需要小心,因为包含是相对于 NDK 根目录的。再次查看文档和示例。
You should really read the ANDROID-MK.html file in the docs directory of the NDK. In short, you can and includes (with LOCAL_C_INCLUDES) and compiler flags (with LOCAL_CFLAGS), and they are passed to the compiler as usual. You need to be careful since includes are relative to the NDK root dir. Again, go over the docs and the examples.