OpenCV with Android NDK Undefined References

久未见 提交于 2020-06-24 12:36:09

问题


I'm trying to use opencv on android (ndk only). I compiled the latest source of the git repository for armeabi. (Based on: Building_OpenCV4Android_from_trunk)

But I'm getting this errors (with ndk-build):

error: undefined reference to 'cv::Mat::deallocate()'
error: undefined reference to 'cv::fastFree(void*)'
error: undefined reference to 'cv::_OutputArray::_OutputArray(cv::Mat&)'
error: undefined reference to 'cv::Mat::copyTo(cv::_OutputArray const&)'
error: undefined reference to 'cv::Mat::inv(int) const'

simple test code:

cv::Mat testMat = cv::Mat(cv::Matx44d
(
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0
));
cv::Mat testMatInv = testMat.inv();

My Android.mk:

LOCAL_C_INCLUDES :=  $(LOCAL_PATH)/../../../../libs/opencv/include
LOCAL_LDLIBS += -L../../../../libs/opencv/lib/android/armeabi
LOCAL_LDLIBS += -llog -lGLESv2 –lz
LOCAL_STATIC_LIBRARIES := libzip libpng libjpeg freetype
LOCAL_STATIC_LIBRARIES += libopencv_calib3d libopencv_contrib libopencv_core libopencv_features2d libopencv_flann libopencv_highgui libopencv_imgproc libopencv_legacy libopencv_ml libopencv_nonfree libopencv_objdetect libopencv_photo libopencv_stitching libopencv_ts libopencv_video libopencv_videostab

Anyone has any clue? Thanks


回答1:


I got it working now. I forgot to add the prebuild libraries in the Android.mk like this:

#same for all other openCV Libs
LOCAL_MODULE := libopencv_calib3d
LOCAL_SRC_FILES := ../../opencv/lib/android/$(TARGET_ARCH_ABI)/libopencv_calib3d.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)

.....
LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_ts libopencv_core



回答2:


Order of libraries matters.

Try:

LOCAL_STATIC_LIBRARIES += libopencv_contrib libopencv_legacy libopencv_ml libopencv_stitching libopencv_nonfree libopencv_objdetect libopencv_videostab libopencv_calib3d libopencv_photo libopencv_video libopencv_features2d libopencv_highgui libopencv_androidcamera libopencv_flann libopencv_imgproc libopencv_core

And recommended way is not hardcode all names in your .mk file but use OpenCV.mk from OpenCV SDK to add OpenCV to your project. (If you are making custom build from source, then OpenCV.mk is generated at cmake (and make install) step.)



来源:https://stackoverflow.com/questions/14649710/opencv-with-android-ndk-undefined-references

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!