码迷,mamicode.com
首页 > 移动开发 > 详细

OpenCV4Android:non-system libraries in linker flags: -lopencv_java错误的解决

时间:2016-02-08 21:28:10      阅读:932      评论:0      收藏:0      [点我收藏+]

标签:

最近搞之前的一份老代码,发现OpenCV到2.4.11之后,之前的mk文件不适用了,报一堆一堆的错误。

一是如前文所述,LOCAL_LDLIBS    += -lm -llog这一句+=绝不能错误的写成:=.另外,还会报这样一个错误:

Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 16 in ./AndroidManifest.xml
Android NDK: WARNING:jni/Android.mk:ProcessImg: non-system libraries in linker flags: -lopencv_java
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK:     current module
[armeabi-v7a] Compile++ thumb: ProcessImg <= DetectFace_JNI.cpp
jni/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

尽管so文件生成了,也安装了,但是报一个non-system libraries in linker flags: -lopencv_java的错误,编译出来的so文件只有330KB左右,理论上这个so应该4.5M左右。运行知道发现找不到libopencv.so. 这是产生这个错误的mk文件:

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.mk
else 
include $(OPENCV_MK_PATH)
endif
LOCAL_LDLIBS    += -lm -llog 
LOCAL_MODULE    := ProcessImg 
LOCAL_SRC_FILES := DetectFace_JNI.cpp 					src/copyToAssets.cpp 					src/detectFace.cpp
					
					
include $(BUILD_SHARED_LIBRARY) 

正确的mk文件应该如下:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

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

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.mk
else 
include $(OPENCV_MK_PATH)
endif

LOCAL_MODULE    := ProcessImg 
LOCAL_SRC_FILES := DetectFace_JNI.cpp 					src/copyToAssets.cpp 					src/detectFace.cpp
					
LOCAL_LDLIBS    += -lm -llog				
include $(BUILD_SHARED_LIBRARY) 

问题就出在:

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

这三句话,尤其是OPENCV_LIB_TYPE:=STATIC是要害,没这一句编译出来的so还是要依赖libopencv_java.so的。而且这句话必须放在include OpenCV.mk文件之前。切记切记!


欢迎加入OpenCV4Android 3群:272250397 备注:yanzi

OpenCV4Android:non-system libraries in linker flags: -lopencv_java错误的解决

标签:

原文地址:http://blog.csdn.net/yanzi1225627/article/details/50644903

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!