Linker error in Text Recognition (OCR) using Tesseract and OpenCV? - visual-studio

I have written the code to recognize text in images using Tesseract and OpenCV.But while I am executing their is no problem with code but it is showing some linker error. I am using tesseract4.0 with visual studios.
#include "stdafx.h"
#include <string>
#include <opencv2/opencv.hpp>
#include "tesseract/baseapi.h"
#include "leptonica/allheaders.h"
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
string outText;
string imPath = "Images/newspaper2.jpeg";
// Create Tesseract object
tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
// Initialize tesseract to use English (eng) and the LSTM OCR engine.
ocr->Init("tessdata", "eng", tesseract::OEM_TESSERACT_ONLY);
// Set Page segmentation mode to PSM_AUTO (3)
ocr->SetPageSegMode(tesseract::PSM_AUTO);
// Open input image using OpenCV
Mat im = imread(imPath, IMREAD_COLOR);
// Set image data
ocr->SetImage(im.data, im.cols, im.rows, 3, im.step);
// Run Tesseract OCR on image
outText = string(ocr->GetUTF8Text());
// print recognized text
cout << outText << endl; // Destroy used object and release memory ocr->End();
return EXIT_SUCCESS;
}
My error looks like this.
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol closesocket opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol connect opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol htons opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol recv opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol select opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol send opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol gethostbyname opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Error LNK2001 unresolved external symbol socket opencv1 C:\Users\Muskan Agarwal\Dropbox\Personal\opencv1\opencv1\tesseract40.lib(svutil.cpp.obj) 1
Thanks for the help.

Figured out the solution to above problem. Actually I was trying to run a 64 bit code and use a32 bit library. So there was a linking error. So now again build tesseract for 32 bit and use it will work. For reference you can see here https://github.com/tesseract-ocr/tesseract/issues/1490.

Related

FASM dll to import from VS

I'm trying to use an import library from a FASM-created DLL to visual studio, no matter what I try I get the unresolved external message.
; proc to export has name exp2
exp2:
....
;
section '.edata' export readable
export 'fasmdll.dll',exp2,'exp2'
The DEF:
LIBRARY FASMDLL
EXPORTS
exp2#4
Then
lib /def:fasmdll.def /out:fasmdll.lib /machine:x86
Then in C++
#pragma comment(lib,"fasmdll.lib")
extern "C" __declspec(dllimport) void __stdcall exp2(DWORD);
The error
dllmain.obj : error LNK2019: unresolved external symbol __imp__exp2#4 referenced in function _exp1#4
If I use __declspec(dllexport) instead I also get
dllmain.obj : error LNK2019: unresolved external symbol _exp2#4
No matter the combination, I can't make it working. Why? In standard Windows libs, the import library wors correctly... I suspect a problem with the DEF file?

Unresolved Error while using stbi_set_flip_vertically_on_load function

I get unresolved symbol error while using stbi_set_flip_vertically_on_load function.
I have added the #include <stb_image.h> file as header , do i need to do something else also ?
stb_image - v2.19
#include <stb_image.h>
stbi_set_flip_vertically_on_load(true); // this gives unresolved symbol error though
You also need to compile stb_image. This should work:
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

using libcurl with chilkat getting errors

i'm using chilkat and libcurl in same project when i build the project with
Runtime Library => Multi-threaded DLL (/MD)
then i get these errors and warning:
Error 4 error LNK1169: one or more multiply defined symbols found
Error 1 error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR90.dll)
Error 2 error LNK2005: __strdup already defined in LIBCMT.lib(strdup.obj)
Warning 3 warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
and when build with
Runtime Library => Multi-threaded (/MT)
Error 54 error LNK1169: one or more multiply defined symbols found
Error 44 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
Error 45 error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
Error 11 error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
Error 39 error LNK2005: __beginthreadex already defined in LIBCMT.lib(threadex.obj)
Error 47 error LNK2005: __close already defined in LIBCMT.lib(close.obj)
...
Chilkat offers both "Multithread DLL" and "Multithread" (i.e. static) libs. Make sure you link with ChilkatRelDll.lib instead of ChilkatRel.lib
Chilkat offers both "Multithread DLL" and "Multithread" (i.e. static) libs. Make sure you link with ChilkatRelDll.lib instead of ChilkatRel.lib
This error occurred due to linking ChilkatRel.lib in Multithread DLL Runtime Project which occurs same lib file more than one time, which occurred multiple definitions of a function. these symbols are present in libcmt.lib
You can resolve this problem by using Runtime Library as Multi-threaded DLL (/MD) and
Adding "libcmt.lib" to the "Ignore Specific Library" field doesn't get me past this problem.

Trouble with OpenCV setup on Visual Studio

I'm trying to setup a simple OpenCV project using Microsoft Visual Studio 2008 in a 64-bit Windows 7 system. I don't have admin rights to the system and as such, I can't go for a fresh installation of OpenCV here.
However, I do have the bin, include and lib directories of OpenCV, compiled on a simillar platform.
I have launched a 'Visual C++ -> General -> Empty Project' and created a .cpp file which reads:
#include <opencv/cv.h>
#include <opencv/highgui.h>
void main()
{
cv::Mat frame = cv::imread("D:\\Images\\lena.bmp");
cv::imwrite("D:\\lena_bw.bmp",frame);
}
In the 'Property->Configuration Property->C/C++->General->Additional Include Directories', I have provided the link to the 'include' directory of OpenCV.
In the 'Property->Configuration Property->Linker->Input->Additional Dependencies', I have provided the path to opencv_core230.lib, opencv_highgui230.lib, opencv_imgproc230.lib etc.
The code builds fine, but when I run it, I get:
Unhandled exception at 0x734761e7 in OpenCVTest.exe: 0xC0000005: Access violation reading location 0xcccccccc.
No symbols are loaded for any call stack frame. The source code cannot be displayed.
I'm getting nowehere with my own ideas. I'm kinda new to the Visual Studio platform.
Please help me figure out a way to make this work.
++++++++++++++++++++++++++++++++++++++++++++++++
When running in 'release' mode, I get the following error during compilation:
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QAE#ABVMat#1##Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPAX#Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QAEXXZ)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" (?imwrite#cv##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV_InputArray#1#ABV?$vector#HV?$allocator#H#std###3##Z)
I am giving you detailed setup instructions that don't need Admin-Rights. Avoid doing things in C drive.
1) Launch VS2010 and select “New project…”.
2) Select “Empty Project”, enter Name, select a location to place project. Press “OK”.
3) Now we have created a project from scratch. It is time to link the libraries and make our project use OpenCV.
Switch to Property manager by clicking on the tab below. If you can’t find the tab, you can access Property manager from menu View.
4) The default properties are for 32-bit systems (note the Win32 suffixes), because you are using 64-bit system, from now on I am going to describe the configuration for 64-bit systems.
If yours is x64 already or you want to work with 32 bit development, leave this step.
From the “Build” menu, select “Configuration Manager”. Under “Active solution platform” Win32 should be selected by default. Click on it and select “New…”.
Select “x64″ as the new platform and select Win32 to copy settings from. Make sure that “Create new project platforms” is checked.
5) INCLUDE
Under “Common Properties” -> “C/C++” -> “General”, edit “Additional Include Directories” and add browse this path to add “..\OpenCV\build\include”. It is important that you select the “include” folder under “build” folder, not any other “include” folder.
6) LINK LIB
Under “Common Properties” -> “Linker” -> “General”, edit “Additional Library Directories” and add “..\OpenCV\build\x64\vc9\lib”. Here “x64″ stands for 64-bit systems, if you are using 32-bit change it to x86. “vc9″ stands for Visual C++ 2008, leave it as it is assuming you are using VS2008, use vc10 for Visual Studio 2010.
7) LIB INPUT
Under “Common Properties” -> “Linker” -> “Input”, edit “Additional Dependencies” and add the following lib files:
[For Debug]
opencv_core242d.lib
opencv_highgui242d.lib
opencv_imgproc242d.lib
[For Release]
opencv_core242.lib
opencv_highgui242.lib
opencv_imgproc242.lib
Here, naming is as: LibName_Version_Debug.lib ie opencv_imgproc242d.lib is opencv_imgproc is library name, 242 is opencv version and d at last indicate debugging library, if you are not using debug mode, don't use library with "d".
I have added very basic libs, you may need to add more according to your code.
8) The steps are the same for “Release” configuration except the linked library filenames. You just need to get rid of the “d” letters before the dot.
Your code should build without any complaints. But while running, you should get an error about a missing dll.
9) DLL
Locate exe/output in your project folder, it's name should be release/debug according to mode of your development and it should have an exe file which is output. Copy the dll files (ends with letter “d” if using debug mode) from “..\OpenCV\build\x64\vc9\bin” (for x64) OR “..\OpenCV\build\x64\vc9\bin” (for 32 bit) and to that folder .
In opencv300 you need opencv_imgcodecs300.lib for imread()/imwrite().

Link Error 2001 when linking to User32.dll

I'm trying to link an object file that uses two methods declared in winuser.h and defined in User32.dll: GetMonitorInfo and WindowFromMonitor. The source compiles to an object file just fine, but when I try to link, I get the following error output:
D3dCtx.obj : error LNK2001: unresolved external symbol xGetMonitorInfo
D3dCtx.obj : error LNK2001: unresolved external symbol xMonitorFromWindow
The thing is, I don't call "xGetMonitorInfo" or "xMonitorFromWindow". Running grep on all source files shows that only "GetMonitorInfo" and "WindowFromMonitor" are being called. I'm properly including windows.h, which includes winuser.h. I'm also properly setting my LIBPATH in the linker options, which is confirmed by verbose link output.
The following also appears in my verbose link output:
Found __imp_GetMonitorInfoA
Referenced in nafxcw.lib(afxribboncategory.obj)
Referenced in nafxcw.lib(afxtooltipctrl.obj)
Referenced in nafxcw.lib(afxribbonkeytip.obj)
Referenced in nafxcw.lib(afxfullscreenimpl.obj)
Referenced in nafxcw.lib(afxframeimpl.obj)
Referenced in nafxcw.lib(afxglobalutils.obj)
Referenced in nafxcw.lib(afxdropdowntoolbar.obj)
Referenced in nafxcw.lib(wincore.obj)
Referenced in nafxcw.lib(afxglobals.obj)
Referenced in nafxcw.lib(afxpopupmenu.obj)
Referenced in nafxcw.lib(afxpropertygridtooltipctrl.obj)
Loaded User32.lib(USER32.dll)
Found __imp_MonitorFromWindow
Referenced in nafxcw.lib(wincore.obj)
Loaded User32.lib(USER32.dll)
Furthermore, GetMonitorInfo is defined in winuser.h as:
WINUSERAPI
BOOL
WINAPI
GetMonitorInfoA(
__in HMONITOR hMonitor,
__inout LPMONITORINFO lpmi);
WINUSERAPI
BOOL
WINAPI
GetMonitorInfoW(
__in HMONITOR hMonitor,
__inout LPMONITORINFO lpmi);
#ifdef UNICODE
#define GetMonitorInfo GetMonitorInfoW
#else
#define GetMonitorInfo GetMonitorInfoA
#endif // !UNICODE
When I change all reference to "GetMonitorInfo" to "GetMonitorInfoA", I only get
D3dCtx.obj : error LNK2001: unresolved external symbol xMonitorFromWindow
as my linker error output. Unfortunately, MonitorFromWindow doesn't seem to have multiple versions available.
I should note that I am using the 64bit versions of the libraries, link, and cl.
What's going on here, and how can I successfully link my program?
I don't know whether you were able to find solution to this or not But I had the same problem and the reason this was happening was that I had a file included named multimon.h
Looks like in case of 64 bit compilation, due to Macro definitions, the definitions of these functions are coming from two sources and probably one from multimon.h is overriding and is wrong.
I solved it by just commenting out this include and it has started to link fine.
//#include <multimon.h>

Resources