C++ Builder XE8 Compiler, Unresolved External (Linker Error) when using AES (Crypto++ 5.6.2)

222 views
Skip to first unread message

Aelon

unread,
Jul 9, 2015, 11:31:23 PM7/9/15
to cryptop...@googlegroups.com
I was trying to compile the tutorial example in this webpage: http://www.cryptopp.com/wiki/Advanced_Encryption_Standard

Specifically the "Encrypting and Decrypting Using AES" part with CFB Mode.

I got several unresolved external linker errors.

So far by trial-and-error, by adding the correct *.cpp modules to the project, I narrowed downed the errors to 4.

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::Resynchronize(const unsigned char *, int)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::UncheckedSetKey(const unsigned char *, unsigned int, CryptoPP::NameValuePairs&)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::ProcessData(unsigned char *, const unsigned char *, unsigned int)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_EncryptionTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::CombineMessageAndShiftRegister(unsigned char *, unsigned char *, const unsigned char *, unsigned int)'

Could you perhaps tell me the correct cpp module to add to the project so that it will link fine ?

And perhaps could you tell me the correct way to setup Crypto++ in C++ Builder XE8 compiler, so that in the future I won't have to add all those "*.cpp" files to the project in order to get rid of linker errors ?

 
--------------------------------------------------------------------------------------------------------------

So far I did these:

- Added Crypto++ 5.6.2 path to the include path list of compiler.

- Added these include lines and directives (Otherwise, naturally it won't recognize names)

#include "aes.h"
#include "osrng.h"
#include "modes.h"
using namespace CryptoPP;

- Added those *.cpp files/modules manually to the project:

"algparam.cpp"
"cpu.cpp"
"cryptlib.cpp"
"filters.cpp"
"fips140.cpp"
"hrtimer.cpp"
"iterhash.cpp"
"misc.cpp"
"modes.cpp"
"mqueue.cpp"
"osrng.cpp"
"queue.cpp"
"randpool.cpp"
"rdtables.cpp"
"rijndael.cpp"
"sha.cpp"
"strciphr.cpp"


By the way, my code is:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
     if (OpenDialog1->Execute() == false) return;

     const String fullfilename = OpenDialog1->FileName;
     const __int64 filesize = GetFileSize (fullfilename);
    
     char* origbuf = new char[filesize];
     char* encrbuf = new char[filesize];
     const NativeUInt filehandle = FileOpen (fullfilename, fmOpenRead | fmShareDenyWrite);
     FileRead (filehandle, origbuf, filesize);
     FileClose (filehandle);

     //---file contents copied to "origbuf", buffer--------------------------------
     //---Tutorial Code starts from here-------------------------------------------------------------------------

     AutoSeededRandomPool rnd;

     // Generate a random key
     SecByteBlock key(0x00, AES::DEFAULT_KEYLENGTH);
     rnd.GenerateBlock( key, key.size() );

     // Generate a random IV
     byte iv[AES::BLOCKSIZE];
     rnd.GenerateBlock(iv, AES::BLOCKSIZE);


     //////////////////////////////////////////////////////////////////////////
     // Encrypt

     CFB_Mode<AES>::Encryption cfbEncryption(key, key.size(), iv);
                                 // dst                source          length
      cfbEncryption.ProcessData((byte*)encrbuf, (byte*)origbuf, filesize);


     // ....

     //----------------------------------------------------------------------------
     delete [] origbuf;
     delete [] encrbuf;
}


Aelon

unread,
Jul 10, 2015, 7:43:37 AM7/10/15
to cryptop...@googlegroups.com
Problem solved and linked fine by also including "strciphr.cpp" and removing the "strciphr.cpp" from modules list.... bah templates..

What I mean is, I included a *.cpp file along with *.h files:


#include "aes.h"
#include "osrng.h"
#include "modes.h"
#include "strciphr.cpp"  // <-- this one...

using namespace CryptoPP;


Is it possible to redesign the contents of strciphr.cpp for Crypto++ library designers to move the template implementations to strciphr.h ? It's rather awkward to include a cpp file.

Jeffrey Walton

unread,
Jul 10, 2015, 7:19:12 PM7/10/15
to cryptop...@googlegroups.com
I got several unresolved external linker errors.

Usually, you just build the library, and then add the entire library to the project.
 
So far by trial-and-error, by adding the correct *.cpp modules to the project, I narrowed downed the errors to 4.

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::Resynchronize(const unsigned char *, int)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::UncheckedSetKey(const unsigned char *, unsigned int, CryptoPP::NameValuePairs&)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_CipherTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::ProcessData(unsigned char *, const unsigned char *, unsigned int)'

[ilink32 Error] Error: Unresolved external 'CryptoPP::CFB_EncryptionTemplate<CryptoPP::AbstractPolicyHolder<CryptoPP::CFB_CipherAbstractPolicy, CryptoPP::CFB_ModePolicy> >::CombineMessageAndShiftRegister(unsigned char *, unsigned char *, const unsigned char *, unsigned int)'

Could you perhaps tell me the correct cpp module to add to the project so that it will link fine ?

Since you are adding source files piecemeal, I *think* the following command will print dependencies. You usually use the command to generate dependencies for Makefiles, but it should work for your purposes, too.

     $(CXX) -MM <sourcefile>

Anywhere you see a *.H file, include the *.CPP file (if it exists).

In you case, I think CXX will be Intel's icpc. Its usually located in /opt/intel or similar.

And perhaps could you tell me the correct way to setup Crypto++ in C++ Builder XE8 compiler, so that in the future I won't have to add all those "*.cpp" files to the project in order to get rid of linker errors ?

You build the library, and then you include the entire library in you Builder XE project. The linker will exclude symbols not needed.

Jeff
Reply all
Reply to author
Forward
0 new messages