Search code examples
androidopencvandroid-ndkjava-native-interface

Can't find OpenCV headers when compiling with ndk-build


When I try and ndk-build my project, I get:

opencv/core/core.hpp: No such file or directory
     #include <opencv/core/core.hpp>
                                    ^

As far as I can see, I've got everything configured correctly:

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# OpenCV
OPENCVROOT:= /.../
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_lib
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8
APP_MODULES := native_lib

What's going wrong? I'm running ndk-build from the command line.

ndk version 10d, OpenCV version 2.4.10.

Here is the verbose output of the compile command:

[armeabi] Compile++ thumb: native_lib <= jni_part.cpp
/Users/me/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ -MMD -MP -MF /Users/me/App/app/src/main/obj/local/armeabi/objs/native_lib//Users/me/App/app/src/main/jni/jni_part.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I/Users/me/App/app/src/main/jni -I/Users/me/App/app/src/debug/jni -I/Users/me/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.8/include -I/Users/me/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi/include -I/Users/me/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.8/include/backward -I/Users/me/App/app/build/intermediates/ndk/debug -DANDROID  -Wa,--noexecstack -Wformat -Werror=format-security    -frtti -fexceptions  -I/Users/me/android-ndk-r10d/platforms/android-8/arch-arm/usr/include -c  /Users/me/App/app/src/main/jni/jni_part.cpp -o /Users/me/App/app/src/main/obj/local/armeabi/objs/native_lib//Users/me/App/app/src/main/jni/jni_part.o

Solution

  • You should add OpenCV's include directory to the LOCAL_C_INCLUDES otherwise the compiler won't find them

    LOCAL_C_INCLUDES := $(OPENCVROOT)/sdk/native/jni/include