1

我正在尝试编译一个在 windows 下使用 tesseract api 的简单示例

Leptonica 1.74.1 是通过 Cmake 和 msbuild 安装的,步骤如下:

mkdir build cd build cmake .. msbuild leptonica.sln

Tesseract 从github下载并编译构建库(修改了 CMAKE_PREFIX_PATH 以添加 LeptonicaConfig.cmake 的路径):

mkdir build cd build cmake .. msbuild tesseract.sln

在这些步骤之后,创建了 dll leptonica-1.74.1d.dll 和 tesseract400d.dll。然后通过带有 makefile 的命令 mingw32-make 编译这个简单的示例:

CPP64 = x86_64-w64-mingw32-g++
CPP32 = g++ -std=c++11
INC_DIR = -I"C:/OCR/tesseract/tesseract/api" -I"C:/OCR/leptonica-1.74.1/src" \
          -I"C:/OCR/tesseract/tesseract/ccutil" -I"C:/OCR/tesseract/tesseract/ccstruct" \
          -I "C:/OCR/tesseract/tesseract/ccmain" -I"C:/OCR/leptonica-1.74.1/build/src"
LINK_DIR = -L"C:/OCR/tesseract/tesseract/build/bin/Debug" -L"C:/OCR/leptonica-1.74.1/build/bin/Debug"
LINK_LIB = -lleptonica-1.74.1d -ltesseract400d
OBJECTS = main.o 
EXECUTABLES = main.exe

all: $(EXECUTABLES)

main.exe: main.o
    $(CPP32) -o $@ $< $(LINK_DIR) $(LINK_LIB)   

main.o: 
    $(CPP32) $(INC_DIR) -c main.cpp

clean:
    rm $(EXECUTABLES) $(OBJECTS)

但是由于未定义的引用,编译失败:

main.o:main.cpp:(.text+0x29): undefined reference to `tesseract::TessBaseAPI::Te ssBaseAPI()' main.o:main.cpp:(.text+0x91): undefined reference to `pixRead' main.o:main.cpp:(.text+0xa4): undefined reference to `tesseract::TessBaseAPI::Se tImage(Pix*)' main.o:main.cpp:(.text+0xb1): undefined reference to `tesseract::TessBaseAPI::Ge tUTF8Text()' main.o:main.cpp:(.text+0xd1): undefined reference to `tesseract::TessBaseAPI::En d()' main.o:main.cpp:(.text+0xed): undefined reference to `pixDestroy' 我检查了问题#377#582但它们没有帮助。似乎 leptonica 和 tesseract dll 都没有正确链接(pixDestroy 函数来自 leptonica,而其他函数来自 tesseract)

4

0 回答 0