Hi all,

I'm trying API examples 
<https://github.com/tesseract-ocr/tesseract/wiki/APIExample#example-using-the-c-api-in-a-c-program>,
 
but I couldn't build the example using ChoiceIterator because of linker 
errors.

Here is my code:
#include "stdafx.h"
#include "allheaders.h"
#include "baseapi.h"
#include <time.h>

using namespace std;
using namespace tesseract;

#pragma comment(lib, "liblept168")
#pragma comment(lib, "libtesseract302")
#pragma comment(lib, "winmm.lib")

int main(int argc, char* argv[])
{
 try
 {
  char *outText;
  const char *path = 
"D:\\160614\\tesseract_testing\\test_texts\\tesseract_training\\";

  TessBaseAPI *api = new TessBaseAPI();
  if (api->Init(path, argv[2])) {
   fprintf(stderr, "Could not initialize tesseract.\n");
   exit(1);
  }
 
  Pix *image = pixRead(argv[1]);
  api->SetImage(image);
  //Get OCR result
  outText = api->GetUTF8Text();
  printf("OCR output:\n%s", outText);

  api->SetImage(image);
  api->SetVariable("save_blob_choices", "T");
  api->SetRectangle(37, 228, 548, 31);
  api->Recognize(NULL);

  tesseract::ResultIterator* ri = api->GetIterator();
  tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
  if (ri != 0) {
   do {
    const char* symbol = ri->GetUTF8Text(level);
    float conf = ri->Confidence(level);
    if (symbol != 0) {
     printf("symbol %s, conf: %f", symbol, conf);
     bool indent = false;
     tesseract::ChoiceIterator ci(*ri);
     do {
      if (indent) printf("\t\t ");
      printf("\t- ");
      const char* choice = ci.GetUTF8Text();
      printf("%s conf: %f\n", choice, ci.Confidence());
      indent = true;
     } while (ci.Next());
    }
    printf("---------------------------------------------\n");
    delete[] symbol;
   } while ((ri->Next(level)));
  }
 }
 catch (...)
 {
 printf("error!");
 }


 return 0;
}

Build output:
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: __thiscall tesseract::ChoiceIterator::ChoiceIterator(class 
tesseract::LTRResultIterator const &)" (??
0ChoiceIterator@tesseract@@QAE@ABVLTRResultIterator@1@@Z)
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: __thiscall tesseract::ChoiceIterator::~ChoiceIterator(void)" 
(??1ChoiceIterator@tesseract@@QAE@XZ)
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: char const * __thiscall 
tesseract::ChoiceIterator::GetUTF8Text(void)const " (?
GetUTF8Text@ChoiceIterator@tesseract@@QBEPBDXZ)
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: float __thiscall 
tesseract::ChoiceIterator::Confidence(void)const " (?
Confidence@ChoiceIterator@tesseract@@QBEMXZ)
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: bool __thiscall tesseract::ChoiceIterator::Next(void)" (?
Next@ChoiceIterator@tesseract@@QAE_NXZ)
1>C:\(my path)\Tesseract-ocr_tutorial_160607\Release\Tesseract-
ocr_tutorial_160607.exe : fatal error LNK1120: 5 unresolved externals

I test one more code:
#include "stdafx.h"
#include "allheaders.h"
#include "baseapi.h"

using namespace std;
using namespace tesseract;

#pragma comment(lib, "liblept168")
#pragma comment(lib, "libtesseract302")

int main(int argc, char* argv[])
{
 tesseract::ResultIterator* ri;
 tesseract::ChoiceIterator ci(*ri);

 return 0;
}

Build output:
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: __thiscall tesseract::ChoiceIterator::ChoiceIterator(class 
tesseract::LTRResultIterator const &)" (??
0ChoiceIterator@tesseract@@QAE@ABVLTRResultIterator@1@@Z)
1>Tesseract-ocr_tutorial_160607.obj : error LNK2001: unresolved external 
symbol "public: __thiscall tesseract::ChoiceIterator::~ChoiceIterator(void)" 
(??1ChoiceIterator@tesseract@@QAE@XZ)
1>C:\(my path)\Tesseract-ocr_tutorial_160607\Release\Tesseract-
ocr_tutorial_160607.exe : fatal error LNK1120: 2 unresolved externals

Other classes are working fine, but ONLY ChoiceIterator is not working.
LTRResultIterator also can be built, although both LTRResultIterator and 
ChoiceIterator are defined in ltrresultiterator.h.
Do you have any suggestions?


Environment
Windows 7
Visual Studio 2013
Tesseract 3.02

Thanks,
Lee.

-- 
You received this message because you are subscribed to the Google Groups 
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/2d17bdc1-5163-45f6-8f9f-5b22b7c110a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to