OpenCV opencv2/core/core.hpp: No such file or directory

10,816

Solution 1

comment out the following from build.gradle (if it is there):

externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

Add this to gradle:

sourceSets.main {
    jni.srcDirs = [] //disable automatic ndk-build call
}

Solution 2

Have you tried only #include <opencv2/core.hpp> (instead of #include <opencv2/core/core.hpp>)? That worked for me (ubuntu 14.04 and opencv 2.4).

Share:
10,816
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm creating a small project to test the opencv (2.4) on Android Studio 1.4 but when I try execute the app I have one problem with the NDK compiler. I think that the cpp files can't find the path to opencv but I dont know why.

    Any ideia how to fix this problem??

    Error:

    /home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.h Error:(10, 33) opencv2/core/core.hpp: No such file or directory

    JNI:

    OpenCV/app/src/main/jni/native_processing.cpp

    OpenCV/app/src/main/jni/native_processing.h

    #ifndef OPENCV_SAMPLE_NATIVE_PROCESSING_H
    #define OPENCV_SAMPLE_NATIVE_PROCESSING_H
    
    #include <jni.h>
    
    #include <opencv2/core/core.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/features2d/features2d.hpp>
    #include <vector>
    
    extern "C" {
    JNIEXPORT void JNICALL      Java_com_projeto_opencv_MainActivity_FindFeatures(JNIEnv *, jobject,
                                                                                     jlong addrGray,
                                                                                     jlong addrRgba);
     }
     #endif
    

    Android.mk

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    OPENCV_LIB_TYPE:=STATIC
    
    
    PENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    OPENCV_LIB_TYPE:=SHARED
    include /home/User/AndroidStudioProjects/OpenCV/OpenCV-android-sdk2/sdk/native/jni/OpenCV.mk
    
    LOCAL_C_INCLUDE :=/home/User/Download/OpenCV-android-sdk2/sdk/native/jni/include
    LOCAL_SRC_FILES := native_processing.cpp
    LOCAL_LDLIBS +=  -llog -ldl
    LOCAL_MODULE:= native_test
    
    
    include $(BUILD_SHARED_LIBRARY)
    

     

    Error: Warning:Native C/C++ source code is found, but it seems that
    NDK option is not configured.  Note that if you have an Android.mk, it is
    not used for compilation.  The recommended workaround is to remove the
    default jni source code directory by adding:
    
     android {
        sourceSets {
            main {
                jni.srcDirs = []
            }
        }
    }    
    
    to build.gradle, manually compile the code with ndk-build, and then
    place the resulting shared object in src/main/jniLibs.
    /home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.cpp
    Information:(1) (Unknown) In file included
    /home/User/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.h
    Error:(10, 33) opencv2/core/core.hpp: No such file or directory
    compilation terminated.
    make: ***
     [/home/User/AndroidStudioProjects/OpenCV/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/app//home/geison/AndroidStudioProjects/OpenCV/app/src/main/jni/native_processing.o] Error 1
    :app:compileDebugNdk FAILED
    Error:Execution failed for task ':app:compileDebugNdk'.
    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/User/Android/Sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2
    
  • Admin
    Admin over 8 years
    didnt work. if I revemo the opencv #includes (#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp>) ... the compiler give me an error in the $include <vector>... i think that the problem isnt on opencv
  • Alex Cohn
    Alex Cohn over 8 years
    Do you define APP_STL in Application.mk? Please post the output of ndk-build V=1
  • Alex Cohn
    Alex Cohn over 8 years
    But if you use gradle plugin to build your .so instead of ndk-build, your Andtoid.mk is irrelevant. What matters is the contents of build.gradle
  • Admin
    Admin over 8 years
    I added the android { sourceSets { main { jni.srcDirs = [] } } } in the build.gradle, it works!