How to use Tesseract on Visual C++ 2015?

905 views
Skip to first unread message

Márcio Porto

unread,
Nov 22, 2015, 8:26:28 AM11/22/15
to tesseract-ocr
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 http://stackoverflow.com/questions/14066074/using-tesseract-ocr-in-vc and http://stackoverflow.com/questions/18180824/how-to-implement-tesseract-to-run-with-project-in-visual-studio-2010. All the tesseract libraries are linked in the right places, but I 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; 

    }


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<class STRING> const *,class GenericVector<class STRING> 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

Thomas

unread,
Aug 10, 2018, 5:27:59 AM8/10/18
to tesseract-ocr
Hello Marco, some time has passed since you posted this issue. I am running into the exact same problem. Did you find the root cause for your errors, and could you solve the issue?
Greetings
Thomas
Reply all
Reply to author
Forward
0 new messages