Correct way of linking crypto++ library with my application

Murtuza Kabul

I am trying to use Crypto++ library in my Qt application.

Qt version is 5.3.0 Compiled with VS2013 running on Windows 8.1

Crypto++ Lib compiled with VS2013

Here is the section of my .pro file which links the lib

win32: LIBS += -L$$PWD/cryptopp562/Win32/DLL_Output/Release/ -lcryptopp

INCLUDEPATH += $$PWD/cryptopp562
DEPENDPATH += $$PWD/cryptopp562

Everything appears to be fine. However I get two issues.

  • I am unable to compile the debug version. I assume that this is because I have release version of .lib file

  • When I try to compile my application, I get the following errors

crypto.obj:-1: error: LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B) referenced in function "public: virtual bool __thiscall CryptoPP::Unflushable::Flush(bool,int,bool)" (?Flush@?$Unflushable@VFilter@CryptoPP@@@CryptoPP@@UAE_N_NH0@Z)

I get two such errors and I assume that this is due to two functions which calls the lib which are not getting compiled.

Edit

My observations:

  • It seems like I am linking to correct static lib, i.e. libcrypt.lib and I have used dumpbin utility to ensure that the missing symbols specified by the error are there in the lib file.

  • It appears that though I am specifying in the .pro file, some how the lib is not being referenced by the project. I have put the following line in my .pro file to reference to static lib

    win32: LIBS += -L$$PWD/cryptopp562/Win32/Output/Release/ -lcryptlib

    INCLUDEPATH += $$PWD/cryptopp562 DEPENDPATH += $$PWD/cryptopp562

    win32:!win32-g++ PRE_TARGETDEPS += $$PWD/cryptopp562/Win32/Output/Release/cryptlib.lib else:win32-g++: PRE_TARGETDEPS += $$PWD/cryptopp562/Win32/Output/Release/libcryptlib.a

My question is,

What mistake I am making ?

What is the correct way to link the Crypto++ lib to Qt project.

jww

I'm going to answer the Edit and Comments in a second block.

After many attempts, finally I am getting this error - cryptlib.lib(cryptlib.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj

Right click on the cryptlib project, and then select Properties.

Notice the Runtime Library. Crypto++ uses the non-DLL runtime libraries by default; and I suspect QT uses the DLL versions of the runtime library by default. Put another way, Crypto++ uses /MT or /MTd by default. And you need /MD or /MDd for Qt integration.

enter image description here

To fix this, have Crypto++ use the DLL version of the runtime library for each Configuration (Debug and Release) and each Platform (Win32 and x64). So your new settings would look like so (notice the addition of DLL):

enter image description here

After making the changes, do a Build → Batch Build → Clean and then a Build → Batch Build → [four static LIBs] as described in the other answer.

Or, you can tell QT to use the non-DLL versions of the runtime library. But nowadays, its usually easiest to use the DLL version of the runtime library for everything.

In either case (change Crypto++ or change Qt), you will still be using the Crypto++ static LIB. The only difference is the static LIB will be built using the DLL version of the runtime library, and not the non-DLL version of the runtime library.

By the way, this was documented some time ago at Static Versus Dynamic Linking at Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment. But I think the solution is unclear.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Correct way to import SpreadJS Charting library in an angular application

What is the correct way to use ECDSA in Crypto++

get CORRECT referrer application on deep linking

Shared library not linking / cannot be done this way?

Linker not linking my own static library

is there a new way of linking Font awesome to my project?

Why does linking libm to library require linking libm to executable using my library?

What is the correct way to make my PyQt application quit when killed from the console (Ctrl-C)?

Linking Rust application with a dynamic library not in the runtime linker search path

Application linking 2 versions of same library due to dependencies

Not able to add library into my application?

Cmake target_link_libraries not linking my library

Why is my C++ ATL project linking in a CIL library?

Why is my shared library not linking correctly when using CMake?

What is correct way to use library installed with CocoaPods?

What is the correct way to install the Carbon library for Android?

Linking challenges with gcc and crypto libraries

How to display a component of my library in my application

Maven: best way of linking custom external JAR to my project?

CSS isn't linking from my Python/Flask application

Is linking with libraries the same as linking to a library linking with libraries

Correct way to restar/reload application for a different release

Correct way to update live django web application

What is the correct way of initializing an elm application

Correct way to load config into Redux application

Correct way to access current application configuration

Correct way to get the instance of Application in android

Correct way to keep writable database for an application

what is the correct way to dockerize express gatsby application?