Force order of linking libraries in Qt Creator - qt

I'm trying to use a 3rd party driver from an app in Qt Creator. This app has to be included as a static library. It won't compile without the /MT flags. After much heartache, I've gotten it down to two linker errors:
msvcrtd.lib(ti_inst.obj):-1: error: LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBCMTD.lib(typinfo.obj)
msvcrtd.lib(ti_inst.obj):-1: error: LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) already defined in LIBCMTD.lib(typinfo.obj)
I think this problem is described here. If that's the case, then I suppose I need to know how to force Qt Creator to link these system libraries in a specific order, when I haven't even included them explicitly in the .pro file in the first place. If someone could tell me how to do that, that'd be great. If, however, this isn't the same problem described on the MS page, an explanation of what I'm really doing wrong, would be even better.

Just to get this marked as answered, I'll quote kanders84152: "Never mind. I was linking against the wrong msvc library. Supposed to use msvcmrt.lib and not msvcurt.lib nor msvcprt.lib. It seems to work now. Thanks, all."

Related

How to build Crypto++ 5.6.2 in for Qt with Visual Studio 2013?

I'm trying to build Crypto++ 5.6.2 in for Qt with Visual Studio 2013, but its producing errors. Here is what I've done so far.
Downloaded Crypto++ 5.6.2
Downloaded vs2010.zip and vs2010-dynamic.zip and overwrite the exiting project files.
The page says this about vs2010-dynamic.zip, but the ZIP includes only cryptest.sln for VS2005. Just a single file. But anyway, I used the file:
archive of a pre-converted solution file, project files and filters for Visual Studio 2010 and above."
I then:
Opened cryptest.sln in MSVC2013, and set "Multi-threaded DLL (/MD)" for each project (project --> properties --> C/C++ --> Code Generation --> Runtime Library --> /MD)
Build --> 'Batch Build' --> Check cryptdll, cryptest, cryptlib, dlltest (Release|win32) --> Build
It resulted in a DLL and LIB in DLL_Output directory. I then:
Moved the DLL to the directory where Qt executable resides.
In Qt, I added two lines to test.pro:
INCLUDEPATH += "../extern/msvc2013/cryptopp562/include"
LIBS += -L"..\extern\msvc2013\cryptopp562\include\cryptopp\Win32\DLL_Output\Release" -lcryptopp
But in Qt, I've got the following errors:
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::GetCurrentTimerValue(void)" (?GetCurrentTimerValue#ThreadUserTimer#CryptoPP##UAE_KXZ)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::TicksPerSecond(void)" (?TicksPerSecond#ThreadUserTimer#CryptoPP##UAE_KXZ)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class CryptoPP::NameValuePairs const & const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs#CryptoPP##3ABVNameValuePairs#1#B) referenced in function "public: __thiscall CryptoPP::HMAC::HMAC(unsigned char const *,unsigned int)" (??0?$HMAC#VSHA256#CryptoPP###CryptoPP##QAE#PBEI#Z)
release\user_account_registration.exe:-1: error: LNK1120: 3 unresolved externals
Do you have any ideas why I am getting the errors?
Any help/comment/insight would be really appreciated.
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::GetCurrentTimerValue(void)" (?GetCurrentTimerValue#ThreadUserTimer#CryptoPP##UAE_KXZ)
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::TicksPerSecond(void)" (?TicksPerSecond#ThreadUserTimer#CryptoPP##UAE_KXZ)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class CryptoPP::NameValuePairs const & const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs#CryptoPP##3ABVNameValuePairs#1#B) referenced in function "public: __thiscall CryptoPP::HMAC::HMAC(unsigned char const *,unsigned int)" (??0?$HMAC#VSHA256#CryptoPP###CryptoPP##QAE#PBEI#Z)
If you look at the source code for hrtimer.h, ThreadUserTimer is missing CRYPTOPP_DLL. That means the DLL does not export ThreadUserTimer (and many other classes).
In general, you should avoid the FIPS DLL unless you have a hard requirement to do so. Its special purpose, and its not easy to work with. It also has Operational Environment requirements from FIPS 140-2. I doubt you want to limit yourself to Visual Studio 2005 and Windows Server 2003.
If you insist on using the FIPS DLL, then you need to link against the DLL as expected. "As expected" means you use the cryptopp.lib import library at compile/link time; and cryptopp.dll at runtime. You also have to link again cryptlib.lib to get the missing classes, like ThreadUserTimer, while setting CRYPTOPP_IMPORTS to avoid duplicate symbols when using both libraries.
Instead of using the DLL, download the updated (and fixed) vs2010-dynamic.zip. Use it to build the Crypto++ library and then use the static library. "Use the static library" means to link against cryptlib.lib only.
The project files from vs2010-dynamic.zip might reference some source files that you don't have because its built from the latest stable sources. If the source file is missing, then simply delete it from the project file. Off the top of my head, Crypto++ 5.6.2 should be missing HKDF, RDRAND, RDSEED, ChaCha, BLAKE2, Base64URLEncoder, Base64URLDecoder, etc. It also lacks the rename of bench.cpp to bench1.cpp.
The Visual Studio wiki page has more information on Windows project files and artifacts like cryptlib.lib.
INCLUDEPATH += ".../cryptopp562/include"
LIBS += -L"...\cryptopp562\include\cryptopp\Win32\DLL_Output\Release" -lcryptopp
I think you should use only -lcryptlib because its the static library, and it has everything you need. The path to the library is $(Platform)\Output\$(Configuration), but I don't know how to translate it into something QT composer can use.
Otherwise, I think you need to specify both -lcryptopp -lcryptlib, and add CRYPTOPP_IMPORTS to preprocessor definitions.
vs2010.zip, vs2010-dynamic.zip and vs2005-dynamic.zip are built from the latest GitHub sources. As of this writing (JUN 1 2016), that's effectively pre-Crypto++ 5.6.4. If you are using the ZIP files with a down level Crypto++, like 5.6.2 or 5.6.3, then you will run into minor problems.
There are two minor problems I am aware. First is a rename of bench.cpp to bench1.cpp. Its error is either:
C1083: Cannot open source file: 'bench1.cpp': No such file or directory
LNK2001: unresolved external symbol "void __cdecl OutputResultOperations(char const *,char const *,bool,unsigned long,double)" (?OutputResultOperations##YAXPBD0_NKN#Z)
The fix is to either (1) open cryptest.vcxproj in notepad, find bench1.cpp, and then rename it to bench.cpp. Or (2) rename bench.cpp to bench1.cpp on the filesystem.
The second problem is a little trickier because its a moving target. Down level releases, like 5.6.2 or 5.6.3, are missing the latest classes available in GitHub. They include HKDF (5.6.3), RDRAND (5.6.3), RDSEED (5.6.3), ChaCha (5.6.4), BLAKE2 (5.6.4), Poly1305 (5.6.4), etc.
The fix is to remove the missing source files from the Visual Studio project files since they don't exist for the down level releases.
Another option is to add the missing class files from the latest sources, but there could be complications. For example, many of the sources subtly depend upon the latest config.h, cpu.h and cpu.cpp. The "subtlety" is you won't realize you are getting an under-performing class.
An example of under-performing class is BLAKE2. config.h adds compile time ARM-32 and ARM-64 detection. cpu.h and cpu.cpp adds runtime ARM instruction detection. If you add BLAKE2 without the other files, then none of the detection occurs and you get a straight C/C++ implementation. The NEON implementation runs around 9 to 12 cycles per byte, while the C/C++ implementation runs around 40 cycles per byte.

'clUnloadCompiler': was declared deprecated when trying to compile OpenCL

I am trying to compile this. I am using the AMD SDK. I am using the header files that come with the aforementioned SDK and they are located in:
C:\Program Files (x86)\AMD APP\include\CL
The tutorial states:
Header files
Just like any other external API used in C++, you must include a header file when using the OpenCLâ„¢ API. Usually, this is in the directory CL within the primary include directory. For the C++ bindings we have (replace the straight C API with cl.h):
I found that last bit a little confusing. I am using both .h and .hpp
#include <CL/cl.h> when this is used it will compile the checkErr function
#include <CL/cl.hpp> when this is used it gives me access to the cl namespace
When I try to compile this code it fails with:
'clUnloadCompiler': was declared deprecated
ADDITIONAL DETAILS (after removing #include <CL/c.h>)
It now gives the following list of errors:
error C4996: Error 2 error LNK2019: unresolved external symbol _clReleaseCommandQueue#4 referenced in function "public: static int __cdecl cl::detail::ReferenceHandler<struct _cl_command_queue *>::release(struct _cl_command_queue *)" (?release#?$ReferenceHandler#PAU_cl_command_queue###detail#cl##SAHPAU_cl_command_queue###Z)
error LNK2019: unresolved external symbol _clReleaseContext#4 referenced in function "public: static int __cdecl cl::detail::ReferenceHandler<struct _cl_context *>::release(struct _cl_context *)" (?release#?$ReferenceHandler#PAU_cl_context###detail#cl##SAHPAU_cl_context###Z)
In properties for my project I have:
added C:\Program Files (x86)\AMD APP\include\ as an additional include directory
added C:\Program Files (x86)\AMD APP\lib\x86_64 as an additional library directory
added OpenCL.lib as an additional dependency
The errors I listed happen regardless of whether or not I take the last two steps. That is, the last two do not seem to be helping or harming anything
Summary of answers I provided in comments:
For a C++ application, you only need to #include <CL/cl.hpp>
Make sure you are linking with the correct OpenCL.lib (32-bit vs. 64-bit).
That's because clUnloadCompiler() was deprecated in OpenCL 1.2.
Add
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
to your code before
#include <CL/cl.h>
#include <CL/cl.hpp>

using QuaZip on Windows with VS2008

I'm using QT4.7.3, VS2008 and trying to add QuaZip library.
I got QuaZip, Zlib and compile it, and then I can make "quazip.lib" file.
I added quazip.lib to "Project property->Configuration Properties->Linker->Input->Additional Dependencies" and include pathes.
I wrote the source code as below.
#include "Updater.h"
#include "quazip.h"
Updater::Updater(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QuaZip *qZip = new QuaZip();
}
but, here, I stuck in problem.
Error message is shown as below.
Updater.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) public: _thiscall QuaZip::QuaZip(void)"
(_imp_??0QuaZip##QAE#XZ) referenced in function "public: __thiscall
Updater::Updater(class QWidget *,class QFlags)"
(??0Updater##QAE#PAVQWidget##V?$QFlags#W4WindowType#Qt#####Z)
1>.\updater.exe : fatal error LNK1120: 1 unresolved externals
I know this error occurs when declaration exists but definition doesn't exists.
As a result of find QuaZip constructor, I found as below.
QuaZip::QuaZip():
p(new QuaZipPrivate(this))
{
}
How can I make it correct?
Thank you for any comment.
I have found the following message in Quazip's README file:
If you want to include QuaZIP sources directly into your project or if
you want to use QuaZIP compiled as a static library using
"qmake CONFIG+=statliclib", you have to define the QUAZIP_STATIC macro,
otherwise you're likely to run into problems as QuaZIP symbols will be
marked as dllimported.
Maybe that will help you.

Qt + Zlib => error LNK2005: _deflate_copyright already defined in QtCored.lib(deflate.obj) zlibstat.lib

When I link my application I receive the following message:
error LNK2005: _deflate_copyright already defined in QtCored.lib(deflate.obj) zlibstat.lib
I'm not sure of the problem, but... I use QT and ZLib. Both are "static libraries". The problem is that the QTCore.lib contains ZLib too!
Project Qt: contains its own version on ZLib.
Project GenericLib: use an external ZLib.lib (cannot be linked to Qt).
Project main: use Qt + Generic lib.
As I say, I'm not sure that it is the problem. But, anyway, if someone has an idea to help me?
Thanks for your help.

Problem statically linking to Botan on Windows using MSVC

I am trying to statically link a Qt library I am building to Botan using MSVC on Windows and am receiving the following error.
..\..\3rdparty\temp\botan-msvc\build\include\botan/secmem.h(129) : error C2589: '(' : illegal token on right side of '::'
..\..\3rdparty\temp\botan-msvc\build\include\botan/secmem.h(128) : while compiling class template member function 'void Botan::MemoryRegion<T>::copy(const T [],size_t)'
with
[
T=Botan::byte
]
..\..\3rdparty\temp\botan-msvc\build\include\botan/buf_comp.h(41) : see reference to class template instantiation 'Botan::MemoryRegion<T>' being compiled
with
[
T=Botan::byte
]
..\..\3rdparty\temp\botan-msvc\build\include\botan/secmem.h(129) : error C2059: syntax error : '::'
This does not occur with MinGW. It also occurs when I comment out all Botan-related code. What does this mean and how can I solve it - also why does it not occur with MinGW?
I was able to figure out the issue with help from Jack Lloyd's comment. Apparently something that's included through one path or another #defined "min". I just undefined it and my library compiles and links perfectly. Thanks Jack!

Resources