0
votes

I am trying to use tesseract in a C++ application, but I can't get it to run in Visual Studio. I am getting a couple of "error LNK2001: unresolved external symbol", which I believe is because Visual Studio can't find the dlls I am trying to use. I have done everything detailed at Using Tesseract OCR in VC++. All the tesseract libraries are linked in the right places, but still can't get it to work. This is what my code looks like:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

using namespace std;

int main(int argc, char *argv[])
{
    char *outText;

    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    // Initialize tesseract-ocr with English, without specifying tessdata path
    if (api->Init(NULL, "eng")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }

    // Open input image with leptonica library
    Pix *image = pixRead("C:\\Users\\Marcio\\PythonProjects\\python_ocr.png");
    api->SetImage(image);
    // Get OCR result
    outText = api->GetUTF8Text();
    printf("OCR output:\n%s", outText);

    // Destroy used object and release memory
    api->End();
    delete[] outText;
    pixDestroy(&image);

    return 0; 

}

EDIT: This is the full error message I get:

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol "public: int __cdecl tesseract::TessBaseAPI::Init(char const *,char const *,enum tesseract::OcrEngineMode,char * *,int,class GenericVector const *,class GenericVector const *,bool)" (?Init@TessBaseAPI@tesseract@@QEAAHPEBD0W4OcrEngineMode@2@PEAPEADHPEBV?$GenericVector@VSTRING@@@@3_N@Z)

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol "public: __cdecl tesseract::TessBaseAPI::TessBaseAPI(void)" (??0TessBaseAPI@tesseract@@QEAA@XZ)

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol pixRead

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol "public: void __cdecl tesseract::TessBaseAPI::SetImage(struct Pix const *)" (?SetImage@TessBaseAPI@tesseract@@QEAAXPEBUPix@@@Z)

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol "public: char * __cdecl tesseract::TessBaseAPI::GetUTF8Text(void)" (?GetUTF8Text@TessBaseAPI@tesseract@@QEAAPEADXZ)

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol "public: void __cdecl tesseract::TessBaseAPI::End(void)" (?End@TessBaseAPI@tesseract@@QEAAXXZ)

1>CallPythonFromC++.obj : error LNK2001: unresolved external symbol pixDestroy

1>C:\Users\Marcio\BlindSight\CallPythonFromCPP\x64\Release\CallPythonFromC++.exe : fatal error LNK1120: 7 unresolved externals

1
We need more info. Copy and paste here full relevant text from Visual Studio. Also, the library apparently has C++ interface, so your build environment must match the build env. of the library (down to service pack). It is not clear what the build env. should be, but even so, if you can't change your build environment, and can't download library that is appropriate for you, then you should download the source code and build your own Tesseract library. And lastly, maybe you can get more help at the appropriate Google forumDialecticus
How do I find out what my build environment should be and how can I change it? Sorry, Visual Studio and C++ newbie in here.MarcioPorto
You tagged your question as Visual Studio 2015. That is your build environment. In your place I would download Tesseract source code and build the library. Or ask for help in the appropriate google forum. And build Leptonica library as well.Dialecticus

1 Answers

0
votes

You have at least to add the following dependencies:

tesseract.lib;openjpeg.lib;libwebp.lib;libtiff.lib;libtesseract.lib;libpng.lib;liblept.lib;libjpeg.lib;jbig2enc.lib;giflib.lib;zlib.lib;

PropertyPages / Linker / Input / Additional Dependencies

Pay attention to your configuration Debug/Release X64 ...