Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way of linking crypto++ library with my application

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.

like image 353
Murtuza Kabul Avatar asked Mar 19 '23 08:03

Murtuza Kabul


1 Answers

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

You can find the versions of the library in their respective folders:

  • Release x64: <cryptopp>\x64\Output\Release
  • Release Win32: <cryptopp>\Win32\Output\Release
  • Debug x64: <cryptopp>\x64\Output\Debug
  • Debug Win32: <cryptopp>\Win32\Output\Debug

I suppose the first step is to make sure you are building them. In Visual Studio, navigate to Build → Batch Build. Then ensure the four cryptlib configurations are checked. Don't worry about the other 20 or so configuration/platform combinations (except maybe cryptest, which you should run for your native platform vis-à-vis cryptest v to run the self tests).

enter image description here

After ensuring they are checked, select Build in the upper left corner.


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)

It sounds like you are linking to the DLL, and not the static LIB. Add CRYPTOPP_IMPORTS to your QT project settings or your precompiled header. Then include the Crypto++ includes. Since you are defining CRYPTOPP_IMPORTS, you do not need to include Crypto++'s dll.h.

With that said, I would recommend abandoning the DLL. The DLL is provided for the FIPS gear, and it might be missing some things you want or need. Instead of the DLL, you should used the static LIB. When using the static LIB, you don't need to worry about defining CRYPTOPP_IMPORTS.

The answer above shows you how to build the Debug and Release versions of the static LIB.

like image 165
jww Avatar answered Apr 07 '23 06:04

jww