OpenCV4Android: non-system libraries in linker flags:-lopencv_java error Solution

Source: Internet
Author: User

OpenCV4Android: non-system libraries in linker flags:-lopencv_java error Solution

Recently I made a copy of the old Code and found that after OpenCV to 2.4.11, the previous mk file was not applicable and a bunch of errors were reported.

First, as described above, the LOCAL_LDLIBS + =-lm-llog sentence + = must not be written incorrectly as: =. In addition, the following error will be reported:

Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 16 in ./AndroidManifest.xmlAndroid NDK: WARNING:jni/Android.mk:ProcessImg: non-system libraries in linker flags: -lopencv_javaAndroid NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIESAndroid NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of theAndroid NDK:     current module[armeabi-v7a] Compile++ thumb: ProcessImg <= DetectFace_JNI.cppjni/DetectFace_JNI.cpp: In function '_jstring* Java_org_yan_processlib_LibProcessImg_processIplImg(JNIEnv*, jobject, jintArray, int, int)':jni/DetectFace_JNI.cpp:97:44: warning: converting 'false' to pointer type for argument 2 of 'jint* _JNIEnv::GetIntArrayElements(jintArray, jboolean*)' [-Wconversion-null]  cbuf = env->GetIntArrayElements(buf, false);                                            ^jni/DetectFace_JNI.cpp: In function '_jstring* Java_org_yan_processlib_LibProcessImg_processStaticImg(JNIEnv*, jobject, jintArray, int, int)':jni/DetectFace_JNI.cpp:131:44: warning: converting 'false' to pointer type for argument 2 of 'jint* _JNIEnv::GetIntArrayElements(jintArray, jboolean*)' [-Wconversion-null]  cbuf = env->GetIntArrayElements(buf, false);                                            ^[armeabi-v7a] Compile++ thumb: ProcessImg <= copyToAssets.cpp[armeabi-v7a] Compile++ thumb: ProcessImg <= detectFace.cpp[armeabi-v7a] SharedLibrary  : libProcessImg.so/Users/yanzi/work/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Users/yanzi/work/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/thumb/libgnustl_static.a(atexit_arm.o) is referenced by DSO /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/../libs/armeabi-v7a/libopencv_java.so[armeabi-v7a] Install        : libProcessImg.so => libs/armeabi-v7a/libProcessImg.so

Although the so file is generated and installed, a non-system libraries in linker flags:-lopencv_java error is reported. The compiled so file is only about KB, in theory, this so should be about 4 MB. The running knows that the libopencv. so cannot be found. This is the mk file that generated this error:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)ifeq ("$(wildcard $(OPENCV_MK_PATH))","") #try to load OpenCV.mk from default install location #include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk include /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/OpenCV.mkelse include $(OPENCV_MK_PATH)endifLOCAL_LDLIBS    += -lm -llog LOCAL_MODULE    := ProcessImg LOCAL_SRC_FILES := DetectFace_JNI.cpp \src/copyToAssets.cpp \src/detectFace.cppinclude $(BUILD_SHARED_LIBRARY) 

The correct mk file should be as follows:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)OpenCV_INSTALL_MODULES:=onOPENCV_CAMERA_MODULES:=offOPENCV_LIB_TYPE:=STATICifeq ("$(wildcard $(OPENCV_MK_PATH))","") #try to load OpenCV.mk from default install location #include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk include /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/OpenCV.mkelse include $(OPENCV_MK_PATH)endifLOCAL_MODULE    := ProcessImg LOCAL_SRC_FILES := DetectFace_JNI.cpp \src/copyToAssets.cpp \src/detectFace.cppLOCAL_LDLIBS    += -lm -lloginclude $(BUILD_SHARED_LIBRARY) 

The problem lies in:

 

OpenCV_INSTALL_MODULES: = on
OPENCV_CAMERA_MODULES: = off
OPENCV_LIB_TYPE: = STATIC

These three statements, especially OPENCV_LIB_TYPE: = STATIC, are crucial. If this sentence is not compiled, so still depends on libopencv_java.so. This statement must be placed before the include OpenCV. mk file.. Remember!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.