I am getting the below errors compiling the cryptopp project in Windows.
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[
__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv]+0x2e): undefined reference to `CryptoPP::AlignedAllocate(unsig
ned int)'
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPv
j[__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj]+0x28): undefined reference to `CryptoPP::AlignedDeallocate
(void*)'
collect2.exe: error: ld returned 1 exit status
Below is my compilation command :
mingw32-g++.exe -o .\aestest2.exe .\aescbc.cpp -I "C:\cryptopp\Include" -L "C:\cryptopp\Lib" -lcryptopp
My libcryptopp.a is located at C:\cryptopp\Lib
I tried to find out where AlignedDeallocate
is declared but I couldn't.
The part of the program that threw this error is below :
try
{
cout << "plain text: " << plain << endl;
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
// The StreamTransformationFilter removes
// padding as required.
StringSource s(plain, true,
new StreamTransformationFilter(e,
new StringSink(cipher)
) // StreamTransformationFilter
); // StringSource
#if 0
StreamTransformationFilter filter(e);
filter.Put((const byte*)plain.data(), plain.size());
filter.MessageEnd();
const size_t ret = filter.MaxRetrievable();
cipher.resize(ret);
filter.Get((byte*)cipher.data(), cipher.size());
#endif
}
catch(const CryptoPP::Exception& e)
{
cerr << e.what() << endl;
exit(1);
}
Suggestions appreciated !
AlignedAllocate
is inmisc.h
:And:
However, they are guarded with:
CRYPTOPP_BOOL_ALIGN16_ENABLED
is set inconfig.h
:You might consider adding the following to
config.h
after Crypto++ makes its choice internally:Then, rebuild the library and your program.
Something else that may be happening is: MinGW is building the library on a machine with MMX/SSE/SSE2 disabled. Or perhaps they are using
g++ -mno-sse -mno-sse2 ...
.Then, you come a long with a shiny new Intel or AMD, and based on what g++ enables and the defines in
config.h
, your program expectsAlignedAllocate
andAlignedDeallocate
because your configuration includes MMX/SSE/SSE2...This situations is discussed at config.h | Recommendations on the Crypto++ wiki. Its why we tell distros to enable and disable things in
config.h
, rather than from the command line. Modifyingconfig.h
ensures the distro and user programs mostly use the same settings.If this is the case, then you might try:
There's a slew of defines that cascade based on MMX/SSE/SSE2; see config.h | Assembly Defines on the wiki. Because MMX/SSE/SSE2 is disabled, you will get a software-only implementation of AES. It won't perform as well as it could.