Search code examples
c++tesseract

Can't make instance of tesseract::TessBaseAPI in c++


I installed tesseract and opencv using vcpkg on macos, everyhitng went fine.

Now i'm trying to make a simple tesseract project with cmake but:

tesseract::TessBaseAPI text_recognizer;

throws:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: collate_byname::collate_byname failed to construct for

Then i changed it to:

tesseract::TessBaseAPI *text_recognizer;

and it doesn't throw any errors, but if i try to initialize it with

text_recognizer = new tesseract::TessBaseAPI();

i get the same as before:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: collate_byname::collate_byname failed to construct for

It'd be enough if someone could point me in the right direction to solve the problem!

EDIT:

Running cmake .. throws the warning:

ld: warning: direct access in function 'unsigned long 
std::__1::__str_find_first_of<char, unsigned long, 
std::__1::char_traits<char>, 18446744073709551615ul>(char const*, 
unsigned long, char const*, unsigned long, unsigned long)' from file 
'../vcpkg/installed/x64- 
osx/debug/lib/libopencv_cored.a(logtagconfigparser.cpp.o)' to global 
weak symbol 'std::__1::char_traits<char>::eq(char, char)' from file 
'CMakeFiles/startProject.dir/main.cpp.o' means the weak symbol cannot 
be overridden at runtime. This was likely caused by different 
translation units being compiled with different visibility settings.

EDIT 2

My CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
set( CMAKE_TOOLCHAIN_FILE "/Users/alejandrocamba/Documents/screen-photo- 
to-text-quality/vcpkg/scripts/buildsystems/vcpkg.cmake" )

project(startProject)

find_package(OpenCV REQUIRED)
find_package(Tesseract CONFIG REQUIRED)
find_package(Leptonica CONFIG REQUIRED)
find_package(libzip REQUIRED)
find_package(libzippp CONFIG REQUIRED)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_executable(startProject main.cpp)

if( OpenCV_FOUND )
  # Additional Include Directories
  include_directories( ${OpenCV_INCLUDE_DIRS} )

  # Additional Library Directories
  link_directories( ${OpenCV_LIB_DIR} )

  # Additional Dependencies
  target_link_libraries(startProject ${OpenCV_LIBS} )
endif()

target_link_libraries(startProject PRIVATE leptonica)
target_link_libraries(startProject PRIVATE libtesseract)
target_link_libraries(startProject PRIVATE zip)
target_link_libraries(startProject PRIVATE libzippp::libzippp)

Solution

  • I wasn't able to find the answer so i started trying random things, and adding

    set(CMAKE_BUILD_TYPE "RELEASE")
    

    Solved the issue for some reason.