title: OpenCV linking error on android
body: <p>I am trying to get <code>OpenCV</code> to work on Android. I have followed several tutorials and no success so far. One approach is <code>OpenCVManager</code>, but when I try the samples they do not work. </p>
  
  <p>The approach I am trying now is to use <code>NDK</code> and add OpenCV through <code>CMake</code> and <code>Android.mk</code>. No success so far. In general, which is the best approach to get started with OpenCV and Android?</p>
  
  <p>I try to just create an empty matrix <code>cv::Mat tmp</code>, but I always get a linking error. </p>
  
  <pre><code>../../../../src/main/jniLibs/jni/include/opencv2/core/mat.inl.hpp:704: error: undefined reference to 'cv::fastFree(void*)'
  </code></pre>
  
  <p>I have tried adding different calls like <code>-lopencv_core</code> and so forth. One thing I am not sure about is actually how to link. There are the static libs that contain <code>libopencv_core.so</code> and so forth. However, <code>jni/libs/</code> only contains <code>libopencv_java3.so</code>.  Exactly which libraries am I supposed to link against and how?</p>
  
  <p><code>CMakeLists.txt</code></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4.1)
  
  include_directories(src/main/jniLibs/jni/include)
  add_library( lib_opencv SHARED IMPORTED )
  set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/libs/${ANDROID_ABI}/libopencv_java3.so)
  add_library( native-lib SHARED src/main/cpp/native-lib.cpp )
  
  
  find_library( # Sets the name of the path variable.
                log-lib
  
                # Specifies the name of the NDK library that
                # you want CMake to locate.
                log )
  
  target_link_libraries( # Specifies the target library.
                         native-lib
  
                         # Links the target library to the log library
                         # included in the NDK.
                         ${log-lib} )
  </code></pre>
  
  <p><code>Android.mk</code></p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  
  include $(CLEAR_VARS)
  
  OPENCV_LIB_TYPE:=SHARED
  OPENCV_CAMERA_MODULES:=on
  OPENCV_INSTALL_MODULES:=on
  
  include {/home/myname/Code/Libraries/Android/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk}
  
  LOCAL_SRC_FILES  += $(LOCAL_PATH)/native-lib.cpp
  LOCAL_C_INCLUDES += {/home/myname/Code/Libraries/Android/OpenCV-android-sdk/sdk/native/jni/include}
  include $(PREBUILT_STATIC_LIBRARY)
  LOCAL_LDLIBS     += -llog -ldl
  LOCAL_CFLAGS    += -DOPENCV_OLDER_VISION
  
  LOCAL_CPP_FEATURES += exceptions (Recommended)
  LOCAL_CPPFLAGS += -fexceptions
  
  
  LOCAL_MODULE     := native-lib
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>