undefined reference to 'cv::imwrite with Android NDK

心已入冬 提交于 2020-07-22 06:26:22

问题


I'm using CMAKE to build OpenALPR, which uses OpenCV.

My CMakeLists.txt contains, among other, the following statements :

# Discover OpenCV directory automatically
find_path(OpenCV_DIR
    NAMES OpenCVConfig.cmake
    HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/
    /storage/projects/alpr/libraries/opencv/
    )

# Opencv Package
FIND_PACKAGE( OpenCV REQUIRED )

#Some code omitted for clarity ...

 TARGET_LINK_LIBRARIES(alpr
    ${OPENALPR_LIB}
    ${STATE_DETECTION_LIB}
    support
    video
    ${OpenCV_LIBS}
    ${Tesseract_LIBRARIES}
    ${Extra_LIBS}
  )

CMake doesn't complain about anything, so I assume OpenCV is found (plus, loads of things are built using OpenCV before the error I'm about to mention).

The instruction I use to build everything :

cmake \
    -DANDROID_TOOLCHAIN=g++ \
    -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
    -DANDROID_NDK=$NDK_ROOT \
    -DCMAKE_BUILD_TYPE=Release \
    -DANDROID_PLATFORM=$ANDROID_PLATFORM \
    -DANDROID_ABI="$i" \
    -DANDROID_STL=c++_shared \
    -DANDROID_CPP_FEATURES="rtti exceptions" \
    -DTesseract_INCLUDE_BASEAPI_DIR=$TESSERACT_SRC_DIR/api \
    -DTesseract_INCLUDE_CCSTRUCT_DIR=$TESSERACT_SRC_DIR/ccstruct \
    -DTesseract_INCLUDE_CCMAIN_DIR=$TESSERACT_SRC_DIR/ccmain \
    -DTesseract_INCLUDE_CCUTIL_DIR=$TESSERACT_SRC_DIR/ccutil \
    -DTesseract_LIB=$TESSERACT_LIB_DIR/libtess.so \
    -DLeptonica_LIB=$TESSERACT_LIB_DIR/liblept.so \
    -DOpenCV_DIR=$SCRIPTPATH/../OpenCV-android-sdk/sdk/native/jni \
    -DJAVA_AWT_LIBRARY=$JAVA_AWT_LIBRARY \
    -DJAVA_JVM_LIBRARY=$JAVA_JVM_LIBRARY \
    -DJAVA_INCLUDE_PATH=$JAVA_INCLUDE_PATH \
    -DJAVA_INCLUDE_PATH2=$JAVA_INCLUDE_PATH2 \
    -DJAVA_AWT_INCLUDE_PATH=$JAVA_AWT_INCLUDE_PATH \
    -DPngt_LIB=$TESSERACT_LIB_DIR/libpngt.so \
    -DJpgt_LIB=$TESSERACT_LIB_DIR/libjpgt.so \
    -DJnigraphics_LIB=$NDK_ROOT/platforms/$ANDROID_PLATFORM/arch-$arch/usr/$lib/libjnigraphics.so \
    -DANDROID_ARM_MODE=arm \
    ../../src/

Notice that I use the Android OpenCV SDK v3.4.3. I have an undefined error :

openalpr/src/misc_utilities/prepcharsfortraining.cpp:224: error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'

The incriminating file has the following include statements :

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <sys/stat.h>
#include "support/filesystem.h"
#include "../tclap/CmdLine.h"
#include "support/utf8.h"

using namespace std;
using namespace cv;
using namespace alpr;

I can't figure out why imwrite cannot be found. I've tried with Android NDK 20, 19, 16 and 14 with no luck

来源:https://stackoverflow.com/questions/57990905/undefined-reference-to-cvimwrite-with-android-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!