Tesseract链接问题

时间:2017-09-27 20:11:36

标签: c++ linker tesseract codelite

我试图从Tesseract GitHub运行非常基本的代码示例时遇到问题。我不知道是不是我无法在搜索查询中表达自己,或者我是否太深。

我有以下代码,从他们页面上的API示例部分复制并粘贴:

#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

int main()
{
    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("/usr/src/tesseract/testing/phototest.tif");
    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;
}

运行此命令会产生以下错误消息:

/home/xweque/Documents/home/docThor/main.cpp:8: undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'
/home/xweque/Documents/home/docThor/main.cpp:16: undefined reference to `pixRead'
/home/xweque/Documents/home/docThor/main.cpp:17: undefined reference to `tesseract::TessBaseAPI::SetImage(Pix*)'
/home/xweque/Documents/home/docThor/main.cpp:19: undefined reference to `tesseract::TessBaseAPI::GetUTF8Text()'
/home/xweque/Documents/home/docThor/main.cpp:23: undefined reference to `tesseract::TessBaseAPI::End()'
/home/xweque/Documents/home/docThor/main.cpp:25: undefined reference to `pixDestroy'
./Debug/main.cpp.o: In function `tesseract::TessBaseAPI::Init(char const*, char const*)':
/usr/include/tesseract/baseapi.h:240: undefined reference to `tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool)'

我正在使用CodeLite 10和g++作为编译器,正式支持。我使用以下作为我唯一的包含路径/usr/include/。两个.h都在那里。我很确定这是一个链接错误,因为我已经尝试了其他代码片段,没有任何正式的,我没有保存,所以没有引用,但给出了指示。

修改

g++输出:

/tmp/ccgCPJv6.o: In function `main':
main.cpp:(.text+0x38): undefined reference to `Magick::InitializeMagick(char const*)'
main.cpp:(.text+0x47): undefined reference to `Magick::Image::Image()'
main.cpp:(.text+0x84): undefined reference to `Magick::Image::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text+0xcc): undefined reference to `Magick::Geometry::Geometry(unsigned int, unsigned int, unsigned int, unsigned int, bool, bool)'
main.cpp:(.text+0xe6): undefined reference to `Magick::Image::crop(Magick::Geometry const&)'
main.cpp:(.text+0xf2): undefined reference to `Magick::Geometry::~Geometry()'
main.cpp:(.text+0x12f): undefined reference to `Magick::Image::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
main.cpp:(.text+0x15e): undefined reference to `Magick::Image::~Image()'
main.cpp:(.text+0x1bb): undefined reference to `Magick::Geometry::~Geometry()'
main.cpp:(.text+0x27b): undefined reference to `Magick::Image::~Image()'
/tmp/ccgCPJv6.o:(.gcc_except_table+0x54): undefined reference to `typeinfo for Magick::Exception'
collect2: error: ld returned 1 exit status

编辑2

xweque@LM-viktor /usr/lib $ ls -la /usr/lib | grep "tesseract"
-rw-r--r--   1 root   root    6741822 Apr  8  2016 libtesseract.a
lrwxrwxrwx   1 root   root         21 Apr  8  2016 libtesseract.so -> libtesseract.so.3.0.4
lrwxrwxrwx   1 root   root         21 Apr  8  2016 libtesseract.so.3 -> libtesseract.so.3.0.4
-rw-r--r--   1 root   root    3074104 Apr  8  2016 libtesseract.so.3.0.4
xweque@LM-viktor /usr/lib $ ls -la /usr/lib | grep "lept"
-rw-r--r--   1 root   root    4592626 Feb  4  2016 liblept.a
lrwxrwxrwx   1 root   root         16 Feb  4  2016 liblept.so -> liblept.so.5.0.0
lrwxrwxrwx   1 root   root         16 Feb  4  2016 liblept.so.5 -> liblept.so.5.0.0
-rw-r--r--   1 root   root    2370000 Feb  4  2016 liblept.so.5.0.0

完整的g ++命令:

g++ -o main /home/xweque/Documents/home/docThor/main.cpp -I/usr/include/ -L/usr/lib/ -llept -ltesseract

0 个答案:

没有答案