Native compilation failed

asked 2018-07-12 15:38:16 -0500

I try use this sample for import openCV sdk to project. I try to port sample from OpenCV sample pack for android. Sample is "face-detection" Everything compiles now except of native code.

From sample I have following function

#include "DetectionBasedTracker_jni.h"
#include "opencv2/core/core.hpp"
#include "o

pencv2/contrib/detection_based_tracker.hpp"

#include <string>
#include <vector>

#include <android/log.h>
#include <jni.h>

...

JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject
(JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
{
    LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject enter");
    const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
    string stdFileName(jnamestr);
    jlong result = 0;
    try
    {
        DetectionBasedTracker::Parameters DetectorParams;
        if (faceSize > 0)
            DetectorParams.minObjectSize = faceSize;
        result = (jlong) new DetectionBasedTracker(stdFileName, DetectorParams);
    }
    catch(cv::Exception& e)
    {
        LOGD("nativeCreateObject caught cv::Exception: %s", e.what());
        jclass je = jenv->FindClass("org/opencv/core/CvException");
        if(!je)
            je = jenv->FindClass("java/lang/Exception");
        jenv->ThrowNew(je, e.what());
    }
    catch (...)
    {
        LOGD("nativeCreateObject caught unknown exception");
        jclass je = jenv->FindClass("java/lang/Exception");
        jenv->ThrowNew(je, "Unknown exception in JNI code of DetectionBasedTracker.nativeCreateObject()");
        return 0;
    }

    LOGD("Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject exit");
    return result;
}

but it does not compile with next error

/llvm-libc++/libs/x86/libandroid_support.a" && :
/Users/busylee/temp/opencv/from-github/app/src/main/cpp/DetectionBasedTracker_jni.cpp:30: error: undefined reference to 'DetectionBasedTracker::DetectionBasedTracker(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, DetectionBasedTracker::Parameters const&)'
/Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86
```
and full error log
```
Build command failed.
Error while executing process /Users/busylee/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/busylee/temp/opencv/from-github/app/.externalNativeBuild/cmake/debug/x86 --target detection_based_tracker}
[1/2] Building CXX object CMakeFiles/detection_based_tracker.dir/src/main/cpp/DetectionBasedTracker_jni.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86/libdetection_based_tracker.so
FAILED: : && /Users/busylee/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/Users/busylee/Library/Android/sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/busylee/Library/Android/sdk/ndk-bundle/sysroot -fPIC -isystem /Users/busylee/Library/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=15 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /Users/busylee/Library/Android/sdk/ndk-bundle/platforms/android-15/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/Users/busylee/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libdetection_based_tracker.so -o ../../../../build/intermediates/cmake/debug/obj/x86/libdetection_based_tracker.so CMakeFiles/detection_based_tracker.dir/src/main/cpp/DetectionBasedTracker_jni.cpp.o  -llog /Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86/libopencv_core.a /Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86/libopencv_androidcamera.a /Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86/libopencv_flann.a /Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86/libopencv_imgproc.a /Users/busylee/temp/opencv/from-github/android-opencv/opencv/src/sdk/native/libs/x86/libopencv_highgui.a ...
(more)
edit retag flag offensive close merge delete