4

I've compiled OpenCV static libraries targeting android armeabi-v7a.

Now I'm trying to link my native C++ code with those libraries through a CMakeLists.txt file in Android Studio but this fails with this weird error :

~/opencv/modules/videoio/src/container_avi.cpp:0: error: undefined reference to 'stderr'

This code comes from the libopencv_videoio.a

The interresting part of the CMakeLists.txt file is this

# linking with static libraries
target_link_libraries(native-lib
     dnn ml objdetect shape stitching superres videostab calib3d features2d highgui videoio imgcodecs video photo imgproc flann core
)

Isn't it supposed to find standard libraries automatically ?

EDIT 1: Following is my Application.mk

...
NDK_TOOLCHAIN_VERSION := clang
APP_PLATFORM := android-21
APP_STL := c++_shared
...

NDK version taken from Changelog.md : r17b

EDIT 2:

As Dan suggested, I've added

"-DANDROID_PLATFORM=android-24"

to the cmake arguments

  • Which NDK version are you using, and which APP_PLATFORM are you targetting (e.g. `android-21`)? – Michael Aug 09 '18 at 13:08
  • The NDK version seems to be r17b –  Aug 09 '18 at 13:24
  • Application.mk does nothing for CMake. – Dan Albert Aug 09 '18 at 17:53
  • CMake and ndk-build are **TWO** different build system for Android native code. CMake is the currently recommended build system but ndk-build is the older way. It doesn't make any sense you have `Application.mk` if you are using CMake build system. – shizhen Aug 10 '18 at 05:14
  • @shizhen thanks for that. –  Aug 10 '18 at 10:49

1 Answers1

5

The most likely scenario is that you built opencv for android-23+ but native-lib has a minSdkVersion below that. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#using-mismatched-prebuilt-libraries.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • 1
    The trick was indeed to add "-DANDROID_PLATFORM=android-24" to compile my native lib –  Aug 10 '18 at 13:30
  • Thanks for the comment Oliver, it worked for me too, but for another project – Pulkit Dec 17 '19 at 19:30