Search code examples
androidg++android-ndkeclipse-cdt

Including library files with Android NDK


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?


Solution

  • 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.