首页 > 解决方案 > 为 android-ndk 构建 opencv 和 tesseract

问题描述

所以我正在尝试为android构建tesseract(使用tess-two)和opencv。我可以分别构建 opencv 和 tess-two,但我希望能够同时构建它们。为此,我使用了与 tess-two 中给出的相同的构建文件。这里调用了所有子目录Android.mk文件,这些文件没有问题。一旦我想包含 opencv 库,并且我想编译依赖于 tesseract 和 opencv 的文件,我就会收到以下错误。

Build command failed.
Error while executing process /home/alexander/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/pathtoapp/app/src/main/cpp/Android.mk NDK_APPLICATION_MK=/pathtoapp/app/src/main/cpp/Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-24 NDK_OUT=/pathtoapp/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/pathtoapp/app/build/intermediates/ndkBuild/debug/lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: WARNING:/pathtoapp/app/src/main/cpp/com_googlecode_tesseract_android/Android.mk:tess: non-system libraries in linker flags: -latomic    
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES    
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the    
Android NDK:     current module    

我不太确定,为什么会发生这个错误。如前所述,我能够单独构建库。所以问题一定是把它们放在一起。这是我的生成文件:

安卓.mk

LOCAL_PATH := $(call my-dir)
TESSERACT_PATH := $(LOCAL_PATH)/com_googlecode_tesseract_android/src
LEPTONICA_PATH := $(LOCAL_PATH)/com_googlecode_leptonica_android/src
LIBJPEG_PATH := $(LOCAL_PATH)/libjpeg
LIBPNG_PATH := $(LOCAL_PATH)/libpng

# Just build the Android.mk files in the subdirs
include $(call all-subdir-makefiles)

####################################################################################

LOCAL_PATH := $(call my-dir)
PROJECT_ROOT:= $(call my-dir)/../../../../..

include $(CLEAR_VARS)

OPENCV_INSTALL_MODULES:=on

LIBOPENCV_PATH := /pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/OpenCV.mk
include $(LIBOPENCV_PATH)

LOCAL_MODULE    := libopencv_ndk
LOCAL_CFLAGS    := -Werror -Wno-write-strings -std=c++11
LOCAL_SRC_FILES := native-lib.cpp \
                   CV_Main.cpp \
                   Native_Camera.cpp \
                   Image_Reader.cpp
LOCAL_LDLIBS    := -llog -landroid -lcamera2ndk -lmediandk
LOCAL_SHARED_LIBRARIES := libtess liblept
include $(BUILD_SHARED_LIBRARY)

我当前的构建目录如下所示:

- com_googlecode_leptonica_android
- com_googlecode_tesseract_android
- libjpeg
- libpng
- opencv

有什么我做错了吗?错误消息是说,我在链接器标志中使用了非系统库: -latomic ,但这似乎不是真正的错误。谁能帮我?

编辑: 我发现了错误是什么。将目标设为 native_lib.cpp 不是规则。所以我无法构建以下 cpp 文件。我通过创建我的$(LOCAL_PATH)的临时变量来修复它。

LOCAL_PATH := $(call my-dir)
MY_PATH := $(LOCAL_PATH)

TESSERACT_PATH := $(LOCAL_PATH)/com_googlecode_tesseract_android/src
LEPTONICA_PATH := $(LOCAL_PATH)/com_googlecode_leptonica_android/src
LIBJPEG_PATH := $(LOCAL_PATH)/libjpeg
LIBPNG_PATH := $(LOCAL_PATH)/libpng

include $(call all-subdir-makefiles)

####################################################################################

include $(CLEAR_VARS)
LOCAL_PATH = $(MY_PATH)

OPENCV_INSTALL_MODULES := on

include /home/alexander/ownCloud/master/fuckarmy/MaritLage/app/src/main/cpp/opencv/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := libopencv_ndk
LOCAL_CFLAGS    := -Werror -Wno-write-strings -std=c++11
LOCAL_SRC_FILES := native-lib.cpp \
                   CV_Main.cpp \
                   Native_Camera.cpp \
                   Image_Reader.cpp
LOCAL_LDLIBS    := -llog -landroid -lcamera2ndk -lmediandk
LOCAL_SHARED_LIBRARIES := libtess liblept
include $(BUILD_SHARED_LIBRARY)

现在,我遇到了一个新问题。

/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `~Mat':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:739: undefined reference to `cv::fastFree(void*)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `Mat':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:548: undefined reference to `cv::error(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, char const*, char const*, int)'
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:561: undefined reference to `cv::error(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, char const*, char const*, int)'
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:568: undefined reference to `cv::Mat::updateContinuityFlag()'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat::operator=(cv::Mat&&)':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:1416: undefined reference to `cv::fastFree(void*)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `CV_Main::detectCard(cv::Mat&)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:287: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:289: undefined reference to `cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:291: undefined reference to `cv::adaptiveThreshold(cv::_InputArray const&, cv::_OutputArray const&, double, int, int, int, double)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:296: undefined reference to `cv::findContours(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int, int, cv::Point_<int>)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:299: undefined reference to `cv::Mat::zeros(cv::Size_<int>, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:305: undefined reference to `cv::arcLength(cv::_InputArray const&, bool)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:305: undefined reference to `cv::approxPolyDP(cv::_InputArray const&, cv::_OutputArray const&, double, bool)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:307: undefined reference to `cv::isContourConvex(cv::_InputArray const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:316: undefined reference to `cv::minAreaRect(cv::_InputArray const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:316: undefined reference to `cv::RotatedRect::boundingRect() const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:357: undefined reference to `cv::fitLine(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, double)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:360: undefined reference to `cv::fitLine(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, double)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:363: undefined reference to `cv::fitLine(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, double)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:366: undefined reference to `cv::fitLine(cv::_InputArray const&, cv::_OutputArray const&, int, double, double, double)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:380: undefined reference to `cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:381: undefined reference to `cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:382: undefined reference to `cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:383: undefined reference to `cv::circle(cv::_InputOutputArray const&, cv::Point_<int>, int, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:408: undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `CV_Main::drawActiveTrader(cv::Mat&)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:472: undefined reference to `cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `compareContour(std::__ndk1::vector<cv::Point_<int>, std::__ndk1::allocator<cv::Point_<int> > >, std::__ndk1::vector<cv::Point_<int>, std::__ndk1::allocator<cv::Point_<int> > >)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:142: undefined reference to `cv::minAreaRect(cv::_InputArray const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:143: undefined reference to `cv::minAreaRect(cv::_InputArray const&)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `Mat<cv::Point_<int> >':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:615: undefined reference to `cv::Mat::copyTo(cv::_OutputArray const&) const'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `project_image(cv::Mat, std::__ndk1::vector<cv::Point_<int>, std::__ndk1::allocator<cv::Point_<int> > >)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:217: undefined reference to `cv::Mat::cross(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:218: undefined reference to `cv::Mat::cross(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:220: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:220: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:221: undefined reference to `cv::Mat::cross(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:222: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:222: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:224: undefined reference to `cv::operator*(double, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:224: undefined reference to `cv::operator-(cv::MatExpr const&, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:225: undefined reference to `cv::operator*(double, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:225: undefined reference to `cv::operator-(cv::MatExpr const&, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:243: undefined reference to `cv::getPerspectiveTransform(cv::Point_<float> const*, cv::Point_<float> const*, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:245: undefined reference to `cv::warpPerspective(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::Size_<int>, int, int, cv::Scalar_<double> const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:252: undefined reference to `cv::Mat::t() const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:253: undefined reference to `cv::Mat::inv(int) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:254: undefined reference to `cv::Mat::inv(int) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:255: undefined reference to `cv::operator*(cv::Mat const&, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:255: undefined reference to `cv::operator*(cv::Mat const&, cv::MatExpr const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:255: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:256: undefined reference to `cv::operator*(cv::Mat const&, cv::Mat const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:256: undefined reference to `cv::operator*(cv::Mat const&, cv::MatExpr const&)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:256: undefined reference to `cv::Mat::dot(cv::_InputArray const&) const'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:272: undefined reference to `cv::getPerspectiveTransform(cv::Point_<float> const*, cv::Point_<float> const*, int)'
/pathtoapp/app/src/main/cpp/CV_Main.cpp:274: undefined reference to `cv::warpPerspective(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::Size_<int>, int, int, cv::Scalar_<double> const&)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `drawLine(cv::Mat*, cv::Vec<double, 4>, int, cv::Scalar_<double>)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:282: undefined reference to `cv::line(cv::_InputOutputArray const&, cv::Point_<int>, cv::Point_<int>, cv::Scalar_<double> const&, int, int, int)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `Mat':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:538: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `CV_Main::detectCardTitleImage(cv::Mat&)':
/pathtoapp/app/src/main/cpp/CV_Main.cpp:454: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat::release()':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:851: undefined reference to `cv::Mat::deallocate()'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat::create(int, int, int)':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:831: undefined reference to `cv::Mat::create(int, int const*, int)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `MatConstIterator':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2621: undefined reference to `cv::MatConstIterator::seek(int const*, bool)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::MatConstIterator::operator++()':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2716: undefined reference to `cv::MatConstIterator::seek(long, bool)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat_<double>::operator=(cv::Mat const&)':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:1709: undefined reference to `cv::Mat::reshape(int, int, int const*) const'
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:1711: undefined reference to `cv::error(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, char const*, char const*, int)'
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:1712: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat::operator=(cv::Mat const&)':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:760: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/opencv_ndk/CV_Main.o: In function `cv::Mat_<double>::operator=(cv::Mat&&)':
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2086: undefined reference to `cv::Mat::reshape(int, int, int const*) const'
/pathtoapp/app/src/main/cpp/opencv/sdk/native/jni/include/opencv2/core/mat.inl.hpp:2090: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/pathtoapp/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libopencv_ndk.so] Error 1

现在虽然似乎无法找到已编译的 opencv 库。问题是什么?谢谢您的帮助!

标签: androidopencvandroid-ndktesseract

解决方案


推荐阅读