Qr read and generation under QT creator using leadtools - c++

I want to buy license for QR codes read and generating from Leadtools but first I want to try their demo tools. I'm using MSVC 2013 x64 compiler. I think I did everything as follows in documentation:
Copied all dll's to my project directory (where build and release folder are located)
Copied Include and Lib folders to my project directory and add this lines to .pro file.
LIBS += -L$$PWD/Lib/CDLLVC12/x64/ -lLtkrn_x
INCLUDEPATH += $$PWD/Include
PRE_TARGETDEPS += $$PWD/Bin/CDLLVC12/x64/Ltkrnx.dll
include and #define LTV19_CONFIG, here is my code:
#define LTV19_CONFIG
#include <iostream>
#include <Ltkrn.h>
#include <ClassLib/LtWrappr.h>
using namespace std;
int main( ){
if( LT_KRN == LBase::LoadLibraries( LT_KRN, LT_DLGKRN))
cout << "success" << endl;
L_TCHAR licenseFile[] = L"d:\\temp\\TestLic.lic";
L_TCHAR key[] = L"xyz123abc";
LSettings::SetLicenseFile( licenseFile, key);
return 0;
}
Ask leadtools support, but they don't have much experience with working with QT...
When I tries to build application I get following errors:
LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl LBase::LoadLibraries(unsigned int,unsigned int)" (__imp_?LoadLibraries#LBase##SAIII#Z) referenced in function main
LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl LSettings::SetLicenseFile(wchar_t *,wchar_t *)" (__imp_?SetLicenseFile#LSettings##SAHPEA_W0#Z) referenced in function main
For following methods documentation says that I only need one dll/lib package (ltkrn). How to fix it? Still I don't get differences between static and dynamic linkage and this could be the problem.

If your linker accepted the 64-bit Ltkrn_x.lib, this suggests the problem is related to how you're using LEADTOOLS and not to QT. That's why I'm posting this as suggested reply instead of a note.
When programming using LEADTOOLS with C++, you normally use one of 2 sets of headers and LIBs:
Either include L_Bitmap.H (or a bunch of headers that includes LtKrn.H) and use the Ltkrn_x, Ltfil_x, etc. set of LIB files.
Or include ClassLib\LtWrappr.h and use only one LIB file, which in your case is Ltwvc_x.lib
Although in both cases you would be using many of the same DLL files such as Ltfilx.dll and Ltkrnx.dll, the reason you don't need their LIB files when using LtWrapper is that the ClassLibrary performs late (on demand) loading of these DLLs at run-time instead of referencing their LIB files at link time.
That's also why you need to call LBase::LoadLibraries() and specify the DLLs you need before your code uses these DLLs.
So to summarize, please try this:
Remove #include "Ltkrn.h"
Remove the linker reference to Ltkrn_x.lib (although you'll need the DLL)
Keep #include "ClassLib/LtWrappr.h"
Add a linker reference to Ltwvc_x.lib

Related

Protobuf - Refuses to link vs2013 or vs2015

As the title states I cannot get protobuf to link successfully.
Here is the small test program. note the AddressBook class was generated usin gthe protoc compiler that was built when i compiled protobuf.Additionally, this proto file is part of googles protobuf examples that is included with the source.
#define PROTOBUF_USE_DLLS
#include <iostream>
#include "addressbook.pb.h"
#pragma comment(lib, "libprotocd.lib")
#pragma comment(lib, "libprotobufd.lib")
#pragma comment(lib, "libprotobuf-lited.lib")
int main(int argc, const char* argv[])
{
tutorial::AddressBook ab;
return 0;
}
Here are the errors I am receiving.
LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const * const google::protobuf::internal::empty_string_" (?empty_string_#internal#protobuf#google##3PEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##EB)
LNK2001: unresolved external symbol "__int64 google::protobuf::internal::empty_string_once_init_" (?empty_string_once_init_#internal#protobuf#google##3_JA)
Some assertions:
Same code running on linux.. With the exception of -lprotoc -lprotobuf -lprotobuf-lite vs. the #pregma stuff
Happens both in VS2013 and VS2015
Tried both 3.0-Release and latest code from git. Same issue.
I have tried this with both the debugtarget as well as the release (when using release removed trailing d from library name) target
Made sure that both the additional include and library directories were set in the VS project. linker --> General --> Additional Library Directories is set to the place where the compiled .dll are located`
At this point I pretty much turned my attention to google to see what I could find. I ran across the following.
2015 not fully supported. It was old, but figured I would try vs2013
protobuf dynamic linking Yes. When building with cmake I enabled shared library support and have the #define in my program
disable inline expansion
Still, not able to progress past the above errors. Any help is greatly appreciated.

Including files from a seperate project in the same solution in Visual studio - LNK2001?

I had a solution named fun.sln with a project called fun.vcxproj.
I created a whole bunch of name spaces ready to be used.
I made another project called no_more_fun.vcxproj.
I added the includes directory for fun.vcxproj to the configuration of no_more_fun.vcxproj.
I added this to no_more_fun.cpp
#include "candy.h"
void main(void)
{
candy::get();
return;
}
candy.h is in the default directory for fun.vcxproj(which was added to the config)
But I get...
LNK2001 unresolved external symbol "int __cdecl candy::get(unsigned long)" (?get#candy##YAHK#Z) .....
Visual Studio shows no error before compiling.
The "candy" namespace works fine in the "fun" project so idn...
Is there a guide or something so that i can understand how i can go about sharing code efficiently among different projects within ONE solution?
This is a linker error. You didn't get any error at compile time, because the compiler found the candy::get() method in candy.h header, but the implementation (which I suppose is in a candy.cpp file) is not found by the linker.
Just add candy.cpp too to no_more_fun.vcxproj.
ps. I didn't observe but in the error message you can see that the function waits a parameter.
call it like this:
unsigned long foo = 0;
candy::get(foo);
This is going to sounds stupid but...i just dragged the files in to visual studio so that the no_more_fun project had the "files" in its "directory" too.
wow... I shouldn't need to do that...Am I wrong?(sarcasm).

OPENCV linking Error - Win32 & VS2012

i have build openCV 3.0.0 both alpha & beta versions. but everytime i run my project i get this Error only for "imread" function:
error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread#cv##YA?AVMat#1#ABVString#1#H#Z) referenced in function _main ...
Here's my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
int main()
{
Mat a=Mat::zeros(10,10,0);
Mat b;
b=imread("Mu.jpg");
imshow("s",a);
waitKey(1000);
}
when i remove the "imread" function it works fine. builds and runs with no errors and displays the little black image (from "A" Matrix)
I have Re-Build the solutions & OpenCV from scratch and still getting this error.
I'm working with VS2012 and i have added the include & lib paths in a property sheet for the project.
Can anyone help with this?
imread function has been moved to imgcodecs library so you have to include it :
For MSVC users : add "opencv_imgcodecs300d.lib" to "configuration properties-> Linker->Input->Aditional Dependencies" and include "#include "
For Qt users : For Qt IDE users add -lopencv_imgcodecs300d or -lopencv_imgcodecs300 to your .pro file
and #include <opencv2/imgcodecs/imgcodecs.hpp> to your main file
note: the number 300 in the lib name should be changed to match OpenCV version used.
This unresolved external symbol linker errors basically arrives when the compiler is not able to get the definition of that function which is declared.
So make sure you have defined imread("Mu.jpg"){} somewhere in your code and then try compiling the same.
Check whether you have linked the libraries properly and also link may be useful if you are using opencv2.2.

Creating static library and linking to it with premake

I am currently trying to learn how to use premake 4 in order to apply it to the OpenGL sdk. I am currently trying to make a Visual Studio 2010 solution that constructs 2 projects, one being a static library, the other contains a single main source file, with the main method.
This project is extremely simple, and is solely for the purpose of learning premake. In the static library project, named Test, I have 2 files, Test.h and Test.cpp. Test.h contains the prototype for the method print(). print() simply prints a line to the console. Using premake, I linked the static library to the Main project, and in main.cpp I have included the Test.h file. My problem is this: in VS2010 I get this error when I attempt to build:
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl print(void)" (? print##YAXXZ) referenced in function _main
1>.\Main.exe : fatal error LNK1120: 1 unresolved externals
Here is my code in the 4 files, the premake4.lua:
solution "HelloWorld"
configurations {"Debug", "Release"}
project "Main"
kind "ConsoleApp"
language "C++"
files{
"main.cpp"
}
configuration "Debug"
defines { "DEBUG" }
flags { "Symbols" }
configuration "Release"
defines { "NDEBUG" }
flags { "Optimize" }
links {"Test"}
project "Test"
kind "StaticLib"
language "C++"
files{
"test.h",
"test.cpp"
}
Test.cpp:
#include <iostream>
void print(){
std::cout << "HELLO" << std::endl;
}
Test.h:
void print();
Main.cpp:
#include <conio.h>
#include "test.h"
int main(){
print();
getch();
return 0;
}
If you are wondering why there is a getch() there, on my computer the console immediately closes once it reaches return 0, so I use getch() to combat that issue, which forces the window to wait until the user has pressed another key. Any advice on this issue would be wonderful, because I simply am not sure what the problem is. If it is something simple please dont castrate me on it, I have very little experience with premake and static libraries, which is why I am trying to learn them.
links {"Test"}
Lua is not Python. Whitespace is irrelevant to Lua, just like whitespace doesn't matter to C++. So your links statement only applies to the "Release" configuration. If you want it to apply to the project as a whole, it needs to go before the configuration statement, just like your kind, files, and other commands.
Premake4 works this way so that you could have certain libraries that are only used in a "Release" build (or Debug or whatever). Indeed, you can put almost any project command under a configuration. So you can have specific files that are used only in a debug build, or whatever.

error LNK2005: new and delete already defined in LIBCMTD.lib(new.obj)

I have a Visual studio 2005 solution that has two projects. One is a static library and the other is a executable used to test the features in the static library. The static library uses MFC. I got the following errors when I built the solution.
uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2#YAPAXI#Z) already defined in LIBCMTD.lib(new.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (?? 3#YAXPAX#Z) already defined in LIBCMTD.lib(dbgdel.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U#YAPAXI#Z) already defined in libcpmtd.lib(newaop.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V#YAXPAX#Z) already defined in LIBCMTD.lib(delete2.obj)
I do not know how to overcome this. Can some one please explain why this error is occuring. Any explanation that gives an overview of .lib files linkage will be highly appreciated.
The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked.
http://support.microsoft.com/kb/148652
Solution based on VS2005 (Replace Nafxcwd.lib with Uafxcwd.lib for ~VS2013)
go to project>properties>configuration properties>linker>input
add to "Additional dependency" -> Nafxcwd.lib Libcmtd.lib
add to "ignore specific library" -> Nafxcwd.lib;Libcmtd.lib
order of libraries is important( Nafxcwd.lib;Libcmtd.lib).
One thing to try is to make sure you have:
#include "stdafx.h"
as the first line in your .cpp files. I'm sure that's not the answer in all cases, but it made the identical error go away in my case.
I meet this problem in a MFC solution of Visual Studio 2010, while changing Use MFC in a Shared DLL into Use MFC in a Static Library in Project -> Properties -> Configuration Properties -> General.
I solve the problem by the following ways, please locate Project -> Properties -> Configuration Properties -> Linker -> Input at first.
In Debug mode:
Add uafxcwd.lib;Libcmtd.lib in Additional Dependencies.
Add uafxcwd.lib;Libcmtd.lib in Ignore Specific Default Libraries.
In Release mode:
Add uafxcw.lib;Libcmt.lib in Additional Dependencies.
Add uafxcw.lib;Libcmt.lib in Ignore Specific Default Libraries.
Notice:
Don't miss the ; between the two .lib files.
A suffix -d must be added in the files in Debug mode.
be sure that you have #include <afx.h> in "stdafx.h" BEFORE other includes like #include <string>
in config linker input
In additional dependicies put uafxcw.lib;LIBCMT.lib
In Ignore specific put put uafxcw.lib;LIBCMT.lib
Make sure the C++ runtime library that you are linking with is the same on your static library as well as your executable. Check your project properties C/C++->Code generation->runtime library settings.
Typo. One stupid way you got that is instead of include the header, you inlucde the cpp.
e.g.
#include <myclass.cpp> //should be #include <myClass.h>
First, libcmtd.lib is for a debug version and libcmt.lib is for production. Double-check that you're not including both. One place to check is the "Command Line" section of the Configuration Properties/Linker project properties.
If you go to the properties for the project, and open up the Configuration Properties/Linker/Input section, you can "Ingore Specific Library"...try listing libcmtd.lib in that field.
For me, I have a static library compiled with _CRTDBG_MAP_ALLOC, and the application not compiled with _CRTDBG_MAP_ALLOC, I was receiving then LNK2005. I've changed the application to compile with _CRTDBG_MAP_ALLOC, and the LNK2005 disappear.
Got rid of the problem
uafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new(unsigned __int64)"
In additional dependicies put uafxcw.lib.
In Ignore specific put put uafxcw.lib.
I had created two fresh projects with VS2017, one was working the other not, so I compared what was the difference. The one working was created with File > New Project > Visual C++ > MFC/ATL > MFC Application the one not working was created with File > New Project > Visual C++ > Windows Desktop > Windows Desktop Wizardthen adding MFC. In both cases I was using MFC as static lib. I had figured out two fixes. But before that we have to add imports because the second project had NONE!
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
Now either of the two fixes worked for me:
Project > Properties > Configuration Properties > General > Use of MFC set it to use in a Shared DLL, this should also automatically set C/C++ > Code Generation > Runtime Library to Multi-threaded debug dll /MDd make sure it indeed did that.
Try compile now, for me it worked.
I noticed the working project had some imports in stdafx.h, I copied them into pch.h in the other project, it worked.(Keeping the properties unchanged, so static lib was used). The code copied was this:
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
The other solutions changing Linker settings I tried them but they did not work.
I would appreciate if somebody knows why my solution works, it is weird, why including those headers in pch.h solves a linker issue whereas including those same headers anywhere else triggers that error??
Check the manifest file of both projects, make sure that they are linking the same version of the standard library. Most likely they are not, check the properties->code generation->standard library linking.
I also had a similar problem. The link given by Donnie explains the the reason. The solution was to look at the error messages and then removing those libs involved and adding those libs in the order of MFC libs first and then CRT libs.
The way to do that in vs2008 is given by ali.
I will also add that if you have replaced the new/delete operators (and if so, please do the array and the scalar both), you may need to tag them as __forceinline so that the obj doesn't collide with the lib.
For example, I did these to force aligned allocations and had the same trouble until I did that:
__forceinline void * operator new(size_t size)
{
return _aligned_malloc(size, 16);
}
__forceinline void operator delete(void* ptr)
{
_aligned_free(ptr);
}
__forceinline void * operator new [](size_t size)
{
return _aligned_malloc(size, 16);
}
__forceinline void operator delete [](void* ptr)
{
_aligned_free(ptr);
}
A header file declared and defined a variable. Possible solutions include:
Declare the variable in .h: extern BOOL MyBool; and then assign to it in a .c or .cpp file: BOOL MyBool = FALSE;.
Declare the variable static.
Declare the variable selectany.
https://msdn.microsoft.com/en-us/library/72zdcz6f.aspx
For me the problem was solved by changing
Project -> Properties -> Configuration Properties -> General: Use of
MFC = Use MFC in a Shared DLL
Before it was set to "Use Standard Windows Libraries"
Additionally I had to set the /MD option under
Project -> Properties -> C/C++ -> Code Generation : Runtime Library =
Multi-threaded DLL (/MD)
Another possible cause that I ran across while searching for this answer:
I accidentally left an #include "StdAfx.h" line at the top of a .cpp file that I moved from the application (which uses precompiled headers) into a shared static library (which doesn't use precompiled headers).
Got errors after applying Cipher Saw's solution to vs2015
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "void __stdcall DDX_Control(class CDataExchange *,int,class CWnd &)" (?DDX_Control##YGXPAVCDataExchange##HAAVCWnd###Z) already defined in uafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "public: int __thiscall CWnd::ExecuteDlgInit(void *)" (?ExecuteDlgInit#CWnd##QAEHPAX#Z) already defined in uafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "public: void __thiscall CMFCDynamicLayout::GetHostWndRect(class CRect &)const " (?GetHostWndRect#CMFCDynamicLayout##QBEXAAVCRect###Z) already defined in uafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "void __cdecl AfxRegisterMFCCtrlClasses(void)" (?AfxRegisterMFCCtrlClasses##YAXXZ) already defined in uafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "protected: void __thiscall CMFCControlContainer::PreUnsubclassControl(class CWnd *)" (?PreUnsubclassControl#CMFCControlContainer##IAEXPAVCWnd###Z) already defined in uafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: int __thiscall CMFCControlContainer::SubclassDlgControls(void)" (?SubclassDlgControls#CMFCControlContainer##QAEHXZ) already defined in uafxcwd.lib(afxctrlcontainer2.obj)
Was able to fix them by changing libs list from uafxcw.lib;Libcmt.lib to afxnmcdd.lib;uafxcwd.lib;Libcmtd.lib (debug unicode build)