OpenCV未定义对`cv :: fastFree(void *)'的引用

时间:2016-03-23 09:20:23

标签: android c++ opencv

我尝试使用OpenCV构建项目,我从官方网站下载了OpenCV SDK 3.1,但在构建期间我收到错误

/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.hpp
Error:(571) undefined reference to 'cv::fastFree(void*)'
Error:(663) undefined reference to 'cv::Mat::create(int, int const*, int)'
Error:(682) undefined reference to 'cv::Mat::deallocate()'

这是我的gradle.build,我使用gradle-experimental:0.4.0

apply plugin: 'com.android.model.application'
model {
android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.2"

    defaultConfig.with {
        applicationId = "pl.mariusz.opencv"
        minSdkVersion.apiLevel = 17
        targetSdkVersion.apiLevel = 23
        versionCode = 1
        versionName = "1.0"
    }

    task ndkBuild(type: Exec) {
        commandLine '/Users/Mario/Library/Android/android-ndk-r10e/ndk-build', '-C', file('src/main').absolutePath
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}
android.ndk {
    moduleName = "source_file"

    cppFlags.add("-std=c++11")
    cppFlags.add("-fexceptions")
    cppFlags.add("-I${file("/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
    cppFlags.add("-I${file("/Users/Mario/Downloads/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString())

    stl = "gnustl_static"//"gnustl_static"//"gnustl_shared"//"stlport_static"
}

android.sources {
    main {
        jni{
            source{
                srcDirs = []
            }
        }
        jniLibs {
            source {
                srcDirs = ['src/main/Libs']
            }

        }
    }
}
android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles.add(file('proguard-rules.txt'))
    }
}

}

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCVROOT:= /Users/Mario/Downloads/OpenCV-android-sdk
OPENCV_LIB_TYPE=STATIC
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES  := source_file.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := source_file

include $(BUILD_SHARED_LIBRARY)

和Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-17

我尝试将它与共享的静态STL混合使用仍有相同的错误,我该如何解决?

[编辑]

libopencv

[溶液]

更像是妥协而不是真正的解决方案,但我将gradle-experimental:0.4.0更改回classpath 'com.android.tools.build:gradle:1.5.0'并将文件gradle.properties添加到项目根目录中

android.useDeprecatedNdk=true

1 个答案:

答案 0 :(得分:1)

您必须将opencv库添加到链接器。要做到这一点,你必须做两件事:1。添加库文件; 2.添加库目录。

尝试

LOCAL_LDLIBS += -llog -ldl -LlibPath -lopencv_calib3d -lopencv_core 

等等,以这种方式添加所有opencv库(或至少是你需要的库)。 -l将自动采用" lib"在文件名和后缀中。 -L将告诉链接器在哪里找到库,因此请添加opencv库文件夹的绝对路径,而不是libPath。见how to mention path of libraries in Android.mk file or Application.mk file?

尝试并告诉我新的错误消息。