Unresolved Error while using stbi_set_flip_vertically_on_load function - stb-image

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>

Related

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

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.

'char' followed by 'char' is illegal in stdint.h line 21

I've been learning CPP a lot recently, this is my first GUI application. It was going well, got buttons and stuff to work.
But after doing little changes to storing and loading resources, VisualStudio starts through this collection of errors from the standard library
Error C2632 'char' followed by 'char' is illegal GUI stdint.h 21
Error C2589 'unsigned': illegal token on right side of '::' GUI cstdint 12
Error C2144 syntax error: 'char' should be preceded by ';' GUI cstdint 12
Error C2873 'unknown-type': symbol cannot be used in a using-declaration GUI cstdint 12
Error C2589 'unsigned': illegal token on right side of '::' GUI cstdint 32
Error C2144 syntax error: 'char' should be preceded by ';' GUI cstdint 32
Error C2873 'unknown-type': symbol cannot be used in a using-declaration GUI cstdint 32
These are all STD files, and I promise I haven't edited them.
The first error char followed by char is thrown on this line
typedef unsigned char uint8_t;
And the rest of the errors are related to that as they are trying to use uint8_t.
Its been working away fine, then just on 1 compile, visual studio decided its own STD files have errors.
I'm not using stdint.h or cstdint (don't know if they are included automatically)
Includes
#using <mscorlib.dll>
#include <windows.h>
#include <urlmon.h>
#include <process.h>
#include <stdio.h>
#include <vcclr.h>
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "Wininet.lib")
#include <Wininet.h>
#include <string>

error C4430: missing type specifier - int assumed?

I have written a callback method and when I am trying to compile the project in vs2012, I am getting the following error:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '&'
the both error present in same line.
These are the following code which I am trying:
#include <windows.h>
#include "atlstr.h"
///////////////////////////////////////////////////////////////////////////////
class CInf;
typedef BOOL (*PENUMDEVCALLBACK)(CInf* inf, const CString& devname, const CString& instsecname, const CStringArray& devid, PVOID context, DWORD& code);
I think the error will be present in CStringArray& argument because when I include the afxcoll.h.
the fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>.
When I removed the windows.h. the above error gone but I need windows.h header also.
Any idea how to include windows.h and afxcoll.h in same file.
It is not possible to include only isolated parts of the MFC. When you want to use CStringArray you Need to include the afx.h or afxwin.h file.
It is possible to use CString alone. If you just want an Array of CString and you don't Need the complete MFC than it is easier to use std::vector. CString works perfect with all STL container.

How to link RtlIpv4StringToAddressExW function?

I am not able to link RtlIpv4StringToAddressExW(). This is a simplified version of my program.
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#include <Windows.h>
#include <cstdio>
#include <MSTcpIP.h>
HRESULT doMAin()
{
LONG error;
PSOCKADDR_IN sin4;
error = RtlIpv4StringToAddressExW(
L"127.0.0.1",
TRUE,
&sin4->sin_addr,
&sin4->sin_port);
return S_OK;
}
And the error I am getting is:
main.obj : error LNK2001: unresolved external symbol __imp__RtlIpv4StringToAddressExW#16
Does anyone know what could be wrong?
"An import library containing the RtlIpv4StringToAddressEx function is not included in the Microsoft Windows Software Development Kit (SDK) released for Windows Vista. The RtlIpv4StringToAddressEx function is included in the Ntdll.lib import library included in the Windows Driver Kit (WDK). An application could also use the GetModuleHandle and GetProcAddress functions to retrieve the function pointer from the Ntdll.dll and call this function."
from the docs.
If there was a lib to pragma comment, it would be Ntdll.lib. To repeat the docs, you can either grab the one from the DDK, or GetProcAddress the sucker.
GetProcAddressing would look like
typedef LONG (NTAPI *pfRtlIpv4StringToAddressEx)(PCWSTR,BOOLEAN,IN_ADDR *,PUSHORT);
pfRtlIpv4StringToAddressEx pRtlIpv4StringToAddressEx = (pfRtlIpv4StringToAddressEx)GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlIpv4StringToAddressExW");
error = (*pRtlIpv4StringToAddressEx)(
L"127.0.0.1",
TRUE,
&sin4->sin_addr,
&sin4->sin_port);

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