未定义的参考:cv :: imencode

时间:2019-01-09 12:19:03

标签: android opencv java-native-interface opencv4android

我正在构建一个简单的Android应用,该应用需要使用OpenCV进行一些处理并将其作为MJPEG流传输。 CV部分是用C ++编写的(起初我使用Java,但是给出了〜12FPS,我需要〜25-30),为了保持较高的FPS,我也想使用套接字在C ++中实现MJPEG服务器。我尝试使用https://github.com/JPery/MJPEGWriter是因为它具有简单的API,并且它使用的所有功能似乎都是在Android NDK中实现的,但是在尝试构建时,出现了以下错误,提示imencode丢失了:

Build command failed.
Error while executing process /Users/jonathano/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/jonathano/frc/code/BugEyed/app/.externalNativeBuild/cmake/debug/x86_64 --target libdbugcv}
[1/2] Building CXX object CMakeFiles/libdbugcv.dir/src/main/jni/libdbugcv.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/liblibdbugcv.so
FAILED: : && /Users/jonathano/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=x86_64-none-linux-android23 --gcc-toolchain=/Users/jonathano/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/jonathano/Library/Android/sdk/ndk-bundle/sysroot -fPIC -isystem /Users/jonathano/Library/Android/sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /Users/jonathano/Library/Android/sdk/ndk-bundle/platforms/android-23/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/Users/jonathano/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,liblibdbugcv.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/liblibdbugcv.so CMakeFiles/libdbugcv.dir/src/main/jni/libdbugcv.cpp.o CMakeFiles/libdbugcv.dir/src/main/jni/libdbugudp.cpp.o CMakeFiles/libdbugcv.dir/src/main/jni/MJPEGWriter.cpp.o  -lGLESv2 /Users/jonathano/frc/code/opencv-android/sdk/native/jni/include/../../libs/x86_64/libopencv_java3.so -landroid -lEGL -llog -lm -latomic -lm "/Users/jonathano/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++_static.a" "/Users/jonathano/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++abi.a" && :
/Users/jonathano/frc/code/BugEyed/app/src/main/jni/MJPEGWriter.cpp:77: error: undefined reference to 'cv::imencode(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<unsigned char, std::__ndk1::allocator<unsigned char> >&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

在链接期间显然存在某种问题,但是我在SO或Google上找到的每个解决方案都无法正常工作。值得一提的是,其他所有OpenCV函数都可以完美运行。

CMakeLists:

cmake_minimum_required(VERSION 3.4.1)

include_directories($ENV{OPENCV_JNI_INCLUDE_DIR})
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(
    lib_opencv
    PROPERTIES
    IMPORTED_LOCATION
    $ENV{OPENCV_JNI_INCLUDE_DIR}/../../libs/${CMAKE_ANDROID_ARCH_ABI}/libopencv_java3.so
)

add_library(
    libdbugcv
    SHARED
    src/main/jni/libdbugcv.cpp
    src/main/jni/libdbugudp.cpp
    src/main/jni/MJPEGWriter.cpp
)

target_link_libraries(
    libdbugcv
    GLESv2
    lib_opencv
    android
    EGL
    log
    m
)

我们使用的OpenCV版本是3.4.4(Android的最新版本)。我该如何解决?

0 个答案:

没有答案