使用tesseract和opencv的cMakefile [英] cMakefile for using tesseract and opencv

查看:48
本文介绍了使用tesseract和opencv的cMakefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是cmake的新手,我正在编写一个使用tesseract的应用程序.g ++命令行工作正常

I am a newbie to cmake and I am writing an application for using tesseract. the g++ command line work fine

g++ -O3 -std=c++11 `pkg-config --cflags --libs tesseract opencv` my_first.cpp -o my_first

但是我写了以下CMakeFile.txt并在Clion中构建,它引发了许多链接错误

But I wrote the following CMakeFile.txt and building in Clion and it throws a bunch of linking errors

cmake_minimum_required(VERSION 2.6)
add_compile_options(-std=c++11)
project (my_first)

find_package(PkgConfig REQUIRED)
pkg_check_modules (OPENCV REQUIRED opencv)
link_directories(${OPENCV_LIBRARY_DIRS})

pkg_check_modules (TESSERACT REQUIRED tesseract)
link_directories(${TESSERACT_LIBRARY_DIRS})

add_executable(myfirst my_first.cpp)

以下是引发的错误

/usr/local/Cellar/cmake/3.11.3/bin/cmake --build 
/Users/ggovindan/tessaract_ocr/tesseract/experiments/cmake-build-debug --target all -- -j 4
[ 50%] Linking CXX executable myfirst
Undefined symbols for architecture x86_64:
  "cv::Mat::deallocate()", referenced from:
      cv::Mat::release() in my_first.cpp.o
  "cv::String::deallocate()", referenced from:
      cv::String::~String() in my_first.cpp.o
      cv::String::operator=(cv::String const&) in my_first.cpp.o
  "cv::String::allocate(unsigned long)", referenced from:
      cv::String::String(std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> > const&) in 
my_first.cpp.o
  "cv::imread(cv::String const&, int)", referenced from:
  _main in my_first.cpp.o
  "cv::fastFree(void*)", referenced from:
    cv::Mat::~Mat() in my_first.cpp.o
  "tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
  _main in my_first.cpp.o
  "tesseract::TessBaseAPI::SetPageSegMode(tesseract::PageSegMode)", referenced from:
  _main in my_first.cpp.o
  "tesseract::TessBaseAPI::Init(char const*, char const*, 
tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, 
GenericVector<STRING> const*, bool)", referenced from:
  tesseract::TessBaseAPI::Init(char const*, char const*, 
tesseract::OcrEngineMode) in my_first.cpp.o
  "tesseract::TessBaseAPI::SetImage(unsigned char const*, int, int, int, int)", referenced from:
  _main in my_first.cpp.o
  "tesseract::TessBaseAPI::TessBaseAPI()", referenced from:
  _main in my_first.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
make[2]: *** [myfirst] Error 1
make[1]: *** [CMakeFiles/myfirst.dir/all] Error 2
make: *** [all] Error 2

推荐答案

这是您需要做的.如果您遇到任何问题,请告诉我.

This is what you need to do.Let me know if you face any problems.

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_EXTENSIONS OFF)

find_package( PkgConfig REQUIRED)

pkg_search_module( TESSERACT REQUIRED tesseract )

pkg_search_module( LEPTONICA REQUIRED lept )

include_directories( ${TESSERACT_INCLUDE_DIRS} )

include_directories( ${LEPTONICA_INCLUDE_DIRS} )

link_directories( ${TESSERACT_LIBRARY_DIRS} )

link_directories( ${LEPTONICA_LIBRARY_DIRS} )

find_package( OpenCV REQUIRED )

include_directories("myfirst.h")

file(GLOB SOURCES "myfirst.cpp")

add_executable(myfirst ${SOURCES})

target_link_libraries( myfirst ${OpenCV_LIBS} )

target_link_libraries( myfirst ${TESSERACT_LIBRARIES} )

target_link_libraries( myfirst ${LEPTONICA_LIBRARIES} )

#install
install(TARGETS myfirst DESTINATION /usr/local/bin)

这篇关于使用tesseract和opencv的cMakefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆