程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> OpenCV4Android:non-system libraries in linker flags: -lopencv_java錯誤的解決

OpenCV4Android:non-system libraries in linker flags: -lopencv_java錯誤的解決

編輯:JAVA綜合教程

OpenCV4Android:non-system libraries in linker flags: -lopencv_java錯誤的解決


最近搞之前的一份老代碼,發現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文件之前。切記切記!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved