{"id":333,"date":"2022-08-30T14:59:36","date_gmt":"2022-08-30T14:59:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/building-native-opencv-for-android-with-eclipse-gives-undefined-reference-to-cvcreatefilecapture-collection-of-common-programming-errors\/"},"modified":"2022-08-30T14:59:36","modified_gmt":"2022-08-30T14:59:36","slug":"building-native-opencv-for-android-with-eclipse-gives-undefined-reference-to-cvcreatefilecapture-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/building-native-opencv-for-android-with-eclipse-gives-undefined-reference-to-cvcreatefilecapture-collection-of-common-programming-errors\/","title":{"rendered":"Building native Opencv for Android with Eclipse gives &ldquo;undefined reference to `cvCreateFileCapture&#39;&rdquo;-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m developing an app with native part which uses embedded OpenCV to extract frames from video file. So far I&#8217;m getting this error:<\/p>\n<pre><code>...\/jni\/ocv.c:12: undefined reference to `cvCreateFileCapture'\n<\/code><\/pre>\n<p>My Android.mk:<\/p>\n<pre><code>LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_MODULE    := ocv\nLOCAL_SRC_FILES := ocv.c\n\ninclude $(BUILD_SHARED_LIBRARY)\n<\/code><\/pre>\n<p>Application.mk:<\/p>\n<pre><code>APP_STL := gnustl_static\nAPP_CPPFLAGS := -frtti -fexceptions\nAPP_ABI := armeabi\n<\/code><\/pre>\n<p>ocv.c:<\/p>\n<pre><code>#include \n#include \n#include \n#include \n#include \n#include \n\njstring Java_com_ice_salvador_MainActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {\n    IplImage* currFrame = 0;\n    CvCapture* cap = 0;\n\n    cap = cvCaptureFromFile(\"\/mnt\/sdcard\/vvv.3gp\"); \/\/test video\n\n    return (*env)-&gt;NewStringUTF(env, \"Hello from native code!\");\n}\n<\/code><\/pre>\n<p>I&#8217;m using OpenCV-2.4.3-android-sdk, Android NDK r8b, Eclipse Juno, Windows.<\/p>\n<p><code>IplImage<\/code>, <code>CvCapture<\/code> gets resolved and the code compiles if I remove the line with <code>cvCaptureFromFile<\/code> &#8211; so I assume I&#8217;m on the right way. I&#8217;m new to JNI and OpenCV. Appreciate your help! Thanks.<\/p>\n<ol>\n<li>\n<p>Not to leave my own question unanswered..<\/p>\n<p>1) I&#8217;ve changed Android.mk to include OpenCV.mk from SDK and to include .so lib into the build:<\/p>\n<pre><code>LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\ninclude c:\\dev\\OpenCV-2.4.3-android-sdk\\sdk\\native\\jni\\OpenCV.mk\n\nLOCAL_MODULE    := ocv\nLOCAL_SRC_FILES := ocv.c\nLOCAL_LDLIBS += -Lc:\\dev\\OpenCV-2.4.3-android-sdk\\sdk\\native\\libs\\armeabi\n\ninclude $(BUILD_SHARED_LIBRARY)\n\n#LOCAL_PATH := \/home\/spatialite\/jni\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := libopencv_java\nLOCAL_SRC_FILES := libopencv_java.so\ninclude $(PREBUILT_SHARED_LIBRARY)\n<\/code><\/pre>\n<p>2) Copied libopencv_java.so to jni\/ folder.<\/p>\n<p>3) Changed java code to:<\/p>\n<pre><code>static {\n  System.loadLibrary(\"opencv_java\");\n  System.loadLibrary(\"ocv\");\n}\n<\/code><\/pre>\n<p>And the error has gone.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:08:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m developing an app with native part which uses embedded OpenCV to extract frames from video file. So far I&#8217;m getting this error: &#8230;\/jni\/ocv.c:12: undefined reference to `cvCreateFileCapture&#8217; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}