Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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  := -DUSE_OPENGL_ES_2_0

LOCAL_CFLAGS += -Wno-write-strings -Wno-psabi $(OPENGLES_DEF)
LOCAL_LDLIBS += -ldl -llog $(OPENGLES_LIB)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/ $(LOCAL_PATH)/../../OpenCV-2.4.6-android-sdk/sdk/native/jni/include
LOCAL_SHARED_LIBRARIES := QCAR-prebuilt Bullet-prebuilt
LOCAL_SRC_FILES := Core.cpp ... etc...
LOCAL_ARM_MODE := arm

include $(BUILD_SHARED_LIBRARY)

And Application.mk file:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9

The problem will be somewhere in my project settings. I am searching google for 2 days but I found nothing useful.

Thanks in advance for any answer.

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  := -DUSE_OPENGL_ES_2_0

LOCAL_CFLAGS += -Wno-write-strings -Wno-psabi $(OPENGLES_DEF)
LOCAL_LDLIBS += -ldl -llog $(OPENGLES_LIB)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/ $(LOCAL_PATH)/../../OpenCV-2.4.6-android-sdk/sdk/native/jni/include
LOCAL_SHARED_LIBRARIES := QCAR-prebuilt Bullet-prebuilt
LOCAL_SRC_FILES := Core.cpp ... etc...
LOCAL_ARM_MODE := arm

include $(BUILD_SHARED_LIBRARY)

And Application.mk file:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9

The problem will be somewhere in my project settings. I am searching searched google for 2 days days, tried every approach, created new project but I found nothing useful.helped.

Thanks in advance for any answer.