Building native Opencv for Android with Eclipse gives “undefined reference to `cvCreateFileCapture'”-Collection of common programming errors

I’m developing an app with native part which uses embedded OpenCV to extract frames from video file. So far I’m getting this error:

.../jni/ocv.c:12: undefined reference to `cvCreateFileCapture'

My Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := ocv
LOCAL_SRC_FILES := ocv.c

include $(BUILD_SHARED_LIBRARY)

Application.mk:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi

ocv.c:

#include 
#include 
#include 
#include 
#include 
#include 

jstring Java_com_ice_salvador_MainActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
    IplImage* currFrame = 0;
    CvCapture* cap = 0;

    cap = cvCaptureFromFile("/mnt/sdcard/vvv.3gp"); //test video

    return (*env)->NewStringUTF(env, "Hello from native code!");
}

I’m using OpenCV-2.4.3-android-sdk, Android NDK r8b, Eclipse Juno, Windows.

IplImage, CvCapture gets resolved and the code compiles if I remove the line with cvCaptureFromFile – so I assume I’m on the right way. I’m new to JNI and OpenCV. Appreciate your help! Thanks.

  1. Not to leave my own question unanswered..

    1) I’ve changed Android.mk to include OpenCV.mk from SDK and to include .so lib into the build:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    include c:\dev\OpenCV-2.4.3-android-sdk\sdk\native\jni\OpenCV.mk
    
    LOCAL_MODULE    := ocv
    LOCAL_SRC_FILES := ocv.c
    LOCAL_LDLIBS += -Lc:\dev\OpenCV-2.4.3-android-sdk\sdk\native\libs\armeabi
    
    include $(BUILD_SHARED_LIBRARY)
    
    #LOCAL_PATH := /home/spatialite/jni
    include $(CLEAR_VARS)
    LOCAL_MODULE := libopencv_java
    LOCAL_SRC_FILES := libopencv_java.so
    include $(PREBUILT_SHARED_LIBRARY)
    

    2) Copied libopencv_java.so to jni/ folder.

    3) Changed java code to:

    static {
      System.loadLibrary("opencv_java");
      System.loadLibrary("ocv");
    }
    

    And the error has gone.

Originally posted 2013-11-06 03:08:36.