Crypto++ and Linux
This week I’ve re-acquainted myself with Linux at work in order to port an app from Windows to Linux. Besides the aggravation of setting up the OS, IDE, and workflow, I had to use a 3rd party library called Crypto++. Well, it wasn’t obvious to set up or figure out so I’d put this out there in case someone has the same problem.
Basically I was able to include the files, but I got a linker error despite including the files in the project file in Qt. This is the error:
g++ -o encrypter -L/usr/lib -Lcryptopp -lcrypto++ -lQtGui -lQtCore -lpthread encrypter.o: In function `CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)': encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x2b): undefined reference to `CryptoPP::AlignedAllocate(unsigned int)' encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x38): undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)' encrypter.o: In function `CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)': encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x25): undefined reference to `CryptoPP::AlignedDeallocate(void*)' encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x32): undefined reference to `CryptoPP::UnalignedDeallocate(void*)' collect2: ld returned 1 exit status make: Leaving directory `/home/alex/projects/encrypter' make: *** [encrypter] Error 1 Exited with code 2. Error while building project encrypter When executing build step 'Make'
The proper way to include crypto++ is NOT to download it from the website. Use terminal to get the library:
sudo apt-get install libcrypto++8 libcrypto++8-dbg libcrypto++-dev
Then check if installed on system:
apt-cache pkgnames | grep -i crypto++
Which should result with:
libcrypto++-utils libcrypto++8 libcrypto++8-dbg libcrypto++-dev libcrypto++-doc
If the information above is different (which is possible if it becomes out of date), check the Crypto++ Linux wiki for instructions.
Now add the library to project with the following linkage (written as a makefile macro, but just put the -L and -I parts in the command line if you’re compiling manually):
LIBS += -L/usr/lib/crypto++ -lcrypto++ INCS += -I/usr/include/crypto++
While is is rather specific, someone out there is probably searching for this so here ya go!
