1

I try to build project with OpenCV, i downloaded OpenCV SDK 3.1 from official website, however during building i get error

/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()'

here is my gradle.build, i use 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)

and Application.mk

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

i tried mix it with shared,static STL with still same error, how can i fix it?

[EDIT]

libopencv

[SOLUTION]

its more like compromise not real solution, but i changed gradle-experimental:0.4.0 back to classpath 'com.android.tools.build:gradle:1.5.0' and added file gradle.properties to project root directory with

android.useDeprecatedNdk=true
Mariusz
  • 1,352
  • 1
  • 16
  • 31
  • you have to add the opencv libraries to the linker, something like `LOCAL_LDLIBS += -llog -ldl -lopencv_core -lopencv_features2d` etc. not sure what their exact names are. – Micka Mar 23 '16 at 09:39
  • `Error:error: cannot find -lopencv_core` tried with -libopencv_core and -llibopencv_code with same result, also for `-lopencv_features2d` – Mariusz Mar 23 '16 at 10:03
  • what are the names of your opencv library files and where are they located in your system? They should have names like libopencv_core.* – Micka Mar 23 '16 at 10:04
  • I think you need add path to your OpenCV libraries to LD_LIBRARY_PATH (where the linker searches for libraries). – LiMuBei Mar 23 '16 at 10:08
  • @Micka i added image what show what name it have and where they are – Mariusz Mar 23 '16 at 10:15
  • @LiMuBei where should i add it – Mariusz Mar 23 '16 at 10:16
  • are you cross-compiling? however, try `export LD_LIBRARY_PATH=/path/to/the/opencv/libs` command before compiling – Micka Mar 23 '16 at 10:21
  • 1
    same error message? You'll have to use the -lopencv_... version, NOT -llibopencv_... etc. I'll write an answer, I can't say whether it works, so please dont downvote. It is easier to adjust advices in the answer than in comments. – Micka Mar 23 '16 at 11:06

1 Answers1

1

You have to add opencv libraries to your linker. To do that, you have to do 2 things: 1. add the library files; 2. add the library directory.

Try

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

and so an, add all the opencv libraries (or at least the ones you'll need) in this way. -l will automatically assume the "lib" in the filename and the suffix. The -L will tell the linker where to find libraries, so instead of libPath please add the absolute path of your opencv library folder. See how to mention path of libraries in Android.mk file or Application.mk file?

Try it and tell me the new error message.

Community
  • 1
  • 1
Micka
  • 19,585
  • 4
  • 56
  • 74
  • `LOCAL_LDLIBS += -llog -ldl -L/Users/Mario/AndroidStudioProjects/SteveAR/app/src/main/libs -lopencv_core` leads to `/Users/Mario/Library/Android/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld Error:error: cannot find -lopencv_core`, its looks like it try to find lib in NDK directory – Mariusz Mar 23 '16 at 11:20
  • sorry, I dont have NDK experience, but try http://stackoverflow.com/questions/20397870/use-external-static-library-in-application-ndk – Micka Mar 23 '16 at 11:38