NDK 编译常见问题总结

1. dlopen failed:"lib_xyz.so"is64-bit instead of 32-bit 这个表示你编译出来的是64bit,但是你应用的地方是32bit,

这时你应该修改一下APP_ABI, from arm64-v8a to armeabi-v7a

#APP_ABI := arm64-v8a
APP_ABI := armeabi-v7a


2.dlsym failed:  undefined symbol: sobel_filter

这表示你可能用C++编译器编译的,需要再编译引用的函数名前extern "C" like this

extern "C" int sobel_filter(uchar* pInImg,uchar* pOutImg,int width,int height);

3. 学会使用dlerror打印错误原因, dl 动态库详解http://blog.csdn.net/jernymy/article/details/6903683

4. 学会使用extern “C" http://www.jianshu.com/p/5d2eeeb93590

5. armeabi-v7a(32位ARM设备),arm64-v8a(64位ARM设备)

6.  applicate.mk 详解 http://blog.sina.com.cn/s/blog_602f877001014ptu.html

一个简单的opencv 例子使用NDK 编译


Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE=STATIC
#include $(OPENCV_ANDROID_ROOT)/sdk/native/jni/OpenCV.mk
include C:/workspace/OpenCV-3.0.0-android-sdk-1/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE    := libplat_recog
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := plat_recog.cpp
#LOCAL_LDLIBS    += -llog -landroid -lEGL -lGLESv1_CM
LOCAL_LDLIBS    += -llog 
#build dynamic library
include $(BUILD_SHARED_LIBRARY)

Application.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE=STATIC
#include $(OPENCV_ANDROID_ROOT)/sdk/native/jni/OpenCV.mk
include C:/workspace/OpenCV-3.0.0-android-sdk-1/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE    := libplat_recog
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := plat_recog.cpp
#LOCAL_LDLIBS    += -llog -landroid -lEGL -lGLESv1_CM
LOCAL_LDLIBS    += -llog 
#build dynamic library
include $(BUILD_SHARED_LIBRARY)

plat_recog.cpp

#include 
#include 
#define  LOG_TAG    "plate_recognition"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
using namespace cv;
extern "C" int sobel_filter(uchar* pInImg,uchar* pOutImg,int width,int height);
int sobel_filter(uchar* pInImg,uchar* pOutImg,int width,int height)
{
  if(pInImg == NULL){
    LOGE("input is null!");
    return -1;
  }
  /*
  CV_8UC1: single channel
  CV_8UC2: two channels
  CV_8UC3: three channels
  */
  Mat srcImg(height,width,CV_8UC1,pInImg);
  Mat outImg(height,width,CV_8UC1,pOutImg);
  Sobel(srcImg, outImg, outImg.depth(), 1, 0, 3);
  imwrite("test.jpg",outImg);
  memcpy(pInImg,pOutImg,width*height);
  LOGE("sobel filter is done");
  return 0;
}




你可能感兴趣的:(NDK 编译常见问题总结)