简体   繁体   中英

Tesseract and Visual C++ 2015

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

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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM