title: 'undefined reference to' the function using Android Studio NDK
body: <p>I have 3 class,native-lib.cpp, tracker.cpp and tracker.hpp,
  However, I am getting an error during build if I use the isTracking function from tracker.cpp in navtive-lib.cpp.</p>
  
  <ul>
  <li>What went wrong:
  Execution failed for task ':app:externalNativeBuildDebug'.
  
  <blockquote>
    <p>Build command failed.
    Error while executing process /home/user/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/user/AndroidStudioProjects/project/app/.externalNativeBuild/cmake/debug/x86 --target tracker}
    [1/2] Building CXX object CMakeFiles/tracker.dir/src/main/cpp/native-lib.cpp.o
    [2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86/libtracker.so
    FAILED: : &amp;&amp; /home/user/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/home/user/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/user/Android/Sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=23 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a --sysroot /home/user/Android/Sdk/ndk-bundle/platforms/android-23/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libtracker.so -o ../../../../build/intermediates/cmake/debug/obj/x86/libtracker.so CMakeFiles/tracker.dir/src/main/cpp/tracker.cpp.o
    CMakeFiles/tracker.dir/src/main/cpp/native-lib.cpp.o  /home/user/Android/Sdk/ndk-bundle/platforms/android-23/arch-x86/usr/lib/liblog.so ../../../../src/main/jniLibs/x86/libopencv_java3.so -lm "/home/user/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" &amp;&amp; :
    /home/user/AndroidStudioProjects/project/app/src/main/cpp/native-lib.cpp:28: error: undefined reference to 'Tracker::isTracking()'
    clang++: </p>
  </blockquote></li>
  </ul>
  
  <p>error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.</p>
  
  <p>My CMakeLists</p>
  
  <pre><code>set (pathToOpenCv /home/user/OpenCV-android-sdk3.2) set (pathToProject /home/user/AndroidStudioProjects/project)
  
  cmake_minimum_required(VERSION 3.4.1)
  
  set(CMAKE_VERBOSE_MAKEFILE on)
  
  include_directories(${pathToOpenCv}/sdk/native/jni/include)
  
  FILE(GLOB_RECURSE cppfiles "/home/user/AndroidStudioProjects/project/app/src/main/cpp/*.cpp")
  
  add_library(lib_opencv SHARED IMPORTED)
  
  add_library(tracker SHARED ${cppfiles})
  
  set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
  
  find_library( log-lib
  
                log ) target_link_libraries(
                         tracker
  
                         ${log-lib}
  
                         lib_opencv
                         )
  </code></pre>
  
  <p>This is my native-lib.cpp</p>
  
  <pre><code>#include &lt;jni.h&gt;
  #include &lt;string&gt;
  #include "tracker.hpp"
  
  using namespace cv;
  
  Tracker tracker;
  
  extern "C"
  JNIEXPORT jboolean JNICALL
  Java_com_example_user_project_Tracker_isTrackingC(JNIEnv *env, jboolean boolean) {
      boolean = tracker.isTracking();
      return boolean;
  }
  </code></pre>
  
  <p>What could be the reason, CMake cannot find my function from tracker.cpp in native-lib? 
  I think I linked all my cpp together by using add_library(tracker SHARED ${cppfiles}) and target_link_libraries in CMakeLists.</p>