LNK2001: unresolved external symbol ""public: void __thiscall tesseract::TessBaseAPI"

40 Views Asked by At

https://tesseract-ocr.github.io/tessdoc/Examples_C++.html

In Windows, to compile the basic example of Tesseract, I created libtesseract-5.lib from libtesseract-5.dll, which I obtained from a prebuilt package. However, I encountered the following linker error:

*1>tessm.obj : error LNK2001: unresolved external symbol "public: void __thiscall tesseract::TessBaseAPI::End(void)" (?End@TessBaseAPI@tesseract@@QAEXXZ)
1>tessm.obj : error LNK2001: unresolved external symbol "public: char * __thiscall tesseract::TessBaseAPI::GetUTF8Text(void)" (?GetUTF8Text@TessBaseAPI@tesseract@@QAEPADXZ)
1>tessm.obj : error LNK2001: unresolved external symbol "public: void __thiscall tesseract::TessBaseAPI::SetImage(struct Pix *)" (?SetImage@TessBaseAPI@tesseract@@QAEXPAUPix@@@Z)
1>tessm.obj : error LNK2001: unresolved external symbol "public: int __thiscall tesseract::TessBaseAPI::Init(char const *,char const *,enum tesseract::OcrEngineMode,char * *,int,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const *,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const *,bool)" (?Init@TessBaseAPI@tesseract@@QAEHPBD0W4OcrEngineMode@2@PAPADHPBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@3_N@Z)
1>tessm.obj : error LNK2001: unresolved external symbol "public: __thiscall tesseract::TessBaseAPI::TessBaseAPI(void)" (??0TessBaseAPI@tesseract@@QAE@XZ)*

To address this, I followed these steps:

a. Extracted the list of exported functions from libtesseract-5.dll to create an exports.def file.

dumpbin /exports libtesseract-5.dll > exports.def

b. Edited exports.def as follows:

LIBRARY libtesseract-5.dll
EXPORTS
    TessAltoRendererCreate    @1
    TessBaseAPIAdaptToWordStr @2
    TessBaseAPIAllWordConfidences @3
    TessBaseAPIAnalyseLayout  @4
    TessBaseAPIClear  @5
    TessBaseAPIClearAdaptiveClassifier    @6
    TessBaseAPIClearPersistentCache   @7
    TessBaseAPICreate @8
    TessBaseAPIDelete @9

c. Used exports.def to create libtesseract-5.lib.

lib /def:exports.def /OUT:libtesseract-5.lib /MACHINE:X86

d. add link of libtesseract-5.lib and I encountered a link error.

Testing

To confirm that all exported functions had the same ordinal in libtesseract-5.dll and libtesseract-5.lib, I generated and compared dll.txt and lib.txt. same exports function counts and same function names confirmed.

dumpbin /exports libtesseract-5.dll > dll.txt

dumpbin /exports libtesseract-5.lib > lib.txt

With link option /verbose I get the following lines, which says I added libtesseract-5.lib and libleptonica.lib correctly.

1>Searching libraries
1>    Searching ..\lib\leptonica\leptonica-1.74.0.lib:
1>    Searching D:\work\Test\YR\x86\OCR\libtesseract-5.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\kernel32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\user32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\gdi32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\winspool.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\comdlg32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\advapi32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\shell32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\ole32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\oleaut32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\uuid.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\odbc32.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\um\x86\odbccp32.lib:
1>    Searching C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\lib\x86\msvcprt.lib:
1>    Searching C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\lib\x86\MSVCRT.lib:
1>      Found ___scrt_stub_for_acrt_initialize
1>        Loaded MSVCRT.lib(ucrt_stubs.obj)
1>      Found __filter_x86_sse2_floating_point_exception_default
1>        Loaded MSVCRT.lib(x86_exception_filter.obj)
1>    Searching C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\lib\x86\OLDNAMES.lib:
1>    Searching C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\lib\x86\vcruntime.lib:
1>    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x86\ucrt.lib:
1>Finished searching libraries

What should I check or test further to obtain the correct libtesseract-5.lib?

0

There are 0 best solutions below