How can one config the STL or STL include in vendor libs’s Android.mk

515 views
Skip to first unread message

Daniel Zhang

unread,
Apr 10, 2019, 12:48:45 PM4/10/19
to android-ndk
Not sure if this is the right forum.  Thanks in advance for any guidance.

An OEM is trying to upgrade OpenCV prebuilt libraries to clang and libc++ and the OpenCV prebuilts are built from ndk-build. There are build breaks while referencing the opencv prebuilt libraries from a vendor module in Android P source tree. (see error below)
Failed at libnvcamerahdr_v3.so: error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)'

Cause:
This build issue seems related to different libc++ inline namespace used by OpenCV prebuilt and vendor module. It is because the vendor module uses external/libcxx/include, the std::vector is compiled to std::__1::vector. Although added LOCAL_LDLIBS := $(TOP)/prebuilts/ndk/r16/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_static.a in Android.mk.
But OpenCV prebuilt uses public ndk r16b, the std::vector is compiled to std::__ndk1::vector.
So can't find defined reference of cv::imwrite in libnvcamerahdr_v3.

Question:
How can we config the STL or STL include in vendor libs’s Android.mk? Tried to set LOCAL_SDK_VERSION and LOCAL_NDK_STL_VARIANT to specify NDK libc++ in vendor module's make file, but it was failed because the vendor module which specified LOCAL_NDK_STL_VARIANT to NDK libc++ cannot access to OpenCV prebuilt library. (see error below)
error: OpenCVTest (native:ndk:libc++:shared) should not link to libopencv_imgcodecs_jetpack (native:vendor).

Android.mk - OpenCV prebuilt library (vendor module)
LOCAL_MODULE := libopencv_imgproc_jetpack
LOCAL_MODULE_TAGS := optional
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/$(JETPACK_OPENCV_PATH)/include
LOCAL_MULTILIB := 64
LOCAL_SRC_FILES_64 := $(JETPACK_OPENCV_PATH_64)/libopencv_imgproc.a
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a

Android.mk - OpenCVTest (vendor module)
LOCAL_MODULE := OpenCVTest
LOCAL_MODULE_TAGS := optional
# Source Files.
LOCAL_SRC_FILES := Main.cpp
# enable exceptions
LOCAL_CFLAGS := -fexceptions -frtti
# Includes.
...
LOCAL_C_INCLUDES += $(OPENCV_PATH)/include
# Prerequisite libraries
...
LOCAL_STATIC_LIBRARIES += libopencv_imgproc_jetpack
...
LOCAL_LDLIBS := $(TOP)/prebuilts/ndk/r16/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_static.a

Dan Albert

unread,
Apr 10, 2019, 1:11:05 PM4/10/19
to android-ndk
If the vendor library is a prebuilt then you can't change it. It's already been built. If you can't rebuild it you need to change your library, not your dependency.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7532c27b-5ed1-46bf-bbbc-e0412a3e6dc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Zhang

unread,
Apr 11, 2019, 2:50:12 PM4/11/19
to android-ndk

partner feedback, would appreciate any guidance.

"We are encountering this issue while upgrading the prebuilt libraries (OpenCV prebuilts) and application (OpenCVTest) to libc++, the layout of std::__1::vector in aosp's libc++ is not the same as in ndk's libc++ ( std::__ndk1::vector), previously don't have this issue with gnustl.In this case, the prebuilt library was built against an ndk's libc++, it is different than the one used to build application (aosp's libc++), what would be the suggested way to update the vendor library, and If we should use the same libc++ STL for application, how to make application using ndk's libc++? (Note that application is a vendor module depends on OpenCV prebuilts and it is built from Android build)"

To unsubscribe from this group and stop receiving emails from it, send an email to andro...@googlegroups.com.

Dan Albert

unread,
Apr 11, 2019, 5:18:23 PM4/11/19
to android-ndk
it is different than the one used to build application (aosp's libc++)

Build the application against the NDK, not the system. You need to set the sdk_version property in your Android.bp (or LOCAL_SDK_VERSION in Android.mk).

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Alex Cohn

unread,
Apr 14, 2019, 11:53:50 PM4/14/19
to android-ndk
The official prebuilt OpenCV libraries use static STL, while the library in external/libcxx is dynamic. You should build OpenCV from sources with external/libcxx, or, as Dan suggested, build the vendor module to link with the static STL implementation from NDK.
Reply all
Reply to author
Forward
0 new messages