Android NDK - many undefined references
Hello,
I successfully built and launched OpenCV sample application for Android but I have problem with integrating OpenCV into my Android NDK project. It already uses Vuforia SDK and Bullet Physics. I want to use OpenCV only in native code (only Kalman Filter).
When I try to compile my project with OpenCV code, I get many undefined reference errors like this:
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function cv::Mat::~Mat():/home/dzony/playground/android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:278: error: undefined reference to 'cv::fastFree(void*)'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function cv::Mat::create(int, int, int):/home/dzony/playground/android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:353: error: undefined reference to 'cv::Mat::create(int, int const*, int)'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function cv::Mat::release():/home/dzony/playground/android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:367: error: undefined reference to 'cv::Mat::deallocate()'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function cv::_InputArray::_InputArray(cv::Scalar_<double> const&):/home/dzony/playground/android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:1135: error: undefined reference to 'vtable for cv::_InputArray'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function CNCAREKF::init():/home/dzony/playground/android/OpenCV-2.4.6-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:1772: error: undefined reference to 'cv::noArray()'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function CNCAREKF::init():jni/CNCAREKF.cpp:45: error: undefined reference to 'cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)'
/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/objs-debug/CNC_AR/CNCAREKF.o: in function __static_initialization_and_destruction_0(int, int):jni/CNCAREKF.cpp:17: error: undefined reference to 'cv::KalmanFilter::KalmanFilter(int, int, int, int)'
I am getting the same results with:
- command line ndk-build / Eclipse
- OpenCV 4.6 / OpenCV 4.4
- Linux / Windows
My Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
#OPENCV_LIB_TYPE:=STATIC
include $(LOCAL_PATH)/../../OpenCV-2.4.6-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_ARM_NEON := true
include $(CLEAR_VARS)
LOCAL_MODULE := QCAR-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libQCAR.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/third-party/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := Bullet-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libbullet.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/third-party/include/Bullet
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := CNC_AR
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF ...