Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
While trying to use the following crypto++ based code in my WIN32 project,I got the following link errors.

What I basically did was to specify the directory where all the .cpp and .h source file of Crypto++ files are located as "Additional include directory" in VS property setting.Note that all the .cpp and .h source files of Crypto++ are in the same directory.
Next, I specified Cryptopp.lib as "Additional Dependency" in VS property setting.
Next, I specified the directory where the debug version of Cryptopp.lib is located as "AdditionalLibrary directory" in VS property setting.
Finally, I copied the dll and placed it in the same directory where my app's executable is.
So,what have I done wrong>>


C++
#include "stdafx.h"
#include "EncryptDecrypt.h"
#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;

#include "filters.h"
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::AuthenticatedEncryptionFilter;
using CryptoPP::AuthenticatedDecryptionFilter;

#include "aes.h"
using CryptoPP::AES;

#include "ccm.h"
using CryptoPP::CCM;

#include "eax.h"
using CryptoPP::EAX;

#include "gcm.h"
using CryptoPP::GCM;

#include "base64.h"



<pre lang="C++">
enum class EnryptType
{
   ENC_EAX, ENC_GCM, ENC_CCM
}


bool Base64Encode(std::string &ciphertext)
{
    std::string encoded;

    try
    {
        CryptoPP::StringSource(ciphertext, true,
            new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
    }
    catch (const std::exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);

        return false;
    }

    ciphertext = encoded;

    return true;
}



<pre lang="C++">
bool Base64Decode(std::string &encoded)
{
    std::string ciphertext;

    try
    {
        CryptoPP::StringSource(encoded, true,
            new CryptoPP::Base64Decoder(new CryptoPP::StringSink(ciphertext)));
    }
    catch (const std::exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);

        return false;
    }

    encoded = ciphertext;

    return true;
}




<pre lang="C++">

std::string CreateKey()
{
    CryptoPP::AutoSeededRandomPool prng;

    byte Key[CryptoPP::AES::DEFAULT_KEYLENGTH];

    prng.GenerateBlock(Key, sizeof(Key));

    std::string stKey;
    for (int i = 0; i < CryptoPP::AES::DEFAULT_KEYLENGTH; i++)
    {
        stKey.push_back(Key[i]);
    }

    return stKey;
}




<pre lang="C++">

bool EncryptData(std::string& message, const std::string& key, EncryptType eEncryptType)
{
    byte iv[AES::BLOCKSIZE];
    memset(iv, 0x00, AES::BLOCKSIZE); // Initialize IV to all zeros
    std::string encryptedMessage;

    try
    {
        if (eEncryptType == EncryptType::ENC_EAX)
        {
            EAX<AES>::Encryption encryptor;
            encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv, sizeof(iv));


            StringSource(message, true,
                new AuthenticatedEncryptionFilter(
                    encryptor,
                    new StringSink(encryptedMessage)
                )
            );
        }
        else if (eEncryptType == EncryptType::ENC_GCM)
        {
            GCM<AES>::Encryption encryptor;
            encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);

            StringSource(message, true,
                new AuthenticatedEncryptionFilter(
                    encryptor,
                    new StringSink(encryptedMessage)
                )
            );
        }
        else if (eEncryptType == EncryptType::ENC_CCM)
        {
            const int TAG_SIZE = 12;// 96 bit authenticator

            CCM<AES, TAG_SIZE>::Encryption encryptor;
            encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
            encryptor.SpecifyDataLengths(0, message.size());

            StringSource(message, true,
                new AuthenticatedEncryptionFilter(
                    encryptor,
                    new StringSink(encryptedMessage)
                )
            );
        }
    }
    catch (const std::exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);

        return false;
    }

    message = encryptedMessage;

    return true;
}




<pre lang="C++"><

bool DecryptData(std::string& encryptedMessage, const std::string& key, EncryptType eEncryptType)
{
    byte iv[AES::BLOCKSIZE];
    memset(iv, 0x00, AES::BLOCKSIZE); // Initialize IV to all zeros
    std::string decryptedMessage;

    try
    {
        if (eEncryptType == EncryptType::ENC_EAX)
        {
            EAX<AES>::Decryption decryptor;
            decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv, sizeof(iv));

            StringSource(encryptedMessage, true,
                new AuthenticatedDecryptionFilter(
                    decryptor,
                    new StringSink(decryptedMessage)
                )
            );
        }
        else if (eEncryptType == EncryptType::ENC_GCM)
        {
            GCM<AES>::Decryption decryptor;
            decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);

            StringSource(encryptedMessage, true,
                new AuthenticatedDecryptionFilter(
                    decryptor,
                    new StringSink(decryptedMessage)
                )
            );
        }
        else if (eEncryptType == EncryptType::ENC_CCM)
        {
            const int TAG_SIZE = 12;// 96 bit authenticator

            CCM<AES, TAG_SIZE>::Decryption decryptor;
            decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
            decryptor.SpecifyDataLengths(0, encryptedMessage.size() - TAG_SIZE);

            StringSource(encryptedMessage, true,
                new AuthenticatedDecryptionFilter(
                    decryptor,
                    new StringSink(decryptedMessage)
                )
            );
        }
    }
    catch (const std::exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);
        return false;
    }

    encryptedMessage = decryptedMessage;

    return true;
}




The following are the link errors:


<pre>Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2001	unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::AuthenticateLastFooterBlock(unsigned char *,unsigned int)" (?AuthenticateLastFooterBlock@EAX_Base@CryptoPP@@MAEXPAEI@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2019	unresolved external symbol "public: virtual void __thiscall CryptoPP::Base64Encoder::IsolatedInitialize(class CryptoPP::NameValuePairs const &)" (?IsolatedInitialize@Base64Encoder@CryptoPP@@UAEXABVNameValuePairs@2@@Z) referenced in function "public: __thiscall CryptoPP::Base64Encoder::Base64Encoder(class CryptoPP::BufferedTransformation *,bool,int)" (??0Base64Encoder@CryptoPP@@QAE@PAVBufferedTransformation@1@_NH@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "public: virtual void __thiscall CryptoPP::Base64Decoder::IsolatedInitialize(class CryptoPP::NameValuePairs const &)" (?IsolatedInitialize@Base64Decoder@CryptoPP@@UAEXABVNameValuePairs@2@@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::SetKeyWithoutResync(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?SetKeyWithoutResync@EAX_Base@CryptoPP@@MAEXPBEIABVNameValuePairs@2@@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::Resync(unsigned char const *,unsigned int)" (?Resync@EAX_Base@CryptoPP@@MAEXPBEI@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::AuthenticateLastHeaderBlock(void)" (?AuthenticateLastHeaderBlock@EAX_Base@CryptoPP@@MAEXXZ)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "protected: virtual unsigned int __thiscall CryptoPP::EAX_Base::AuthenticateBlocks(unsigned char const *,unsigned int)" (?AuthenticateBlocks@EAX_Base@CryptoPP@@MAEIPBEI@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2019	unresolved external symbol "private: static int const * __cdecl CryptoPP::Base64Decoder::GetDecodingLookupArray(void)" (?GetDecodingLookupArray@Base64Decoder@CryptoPP@@CAPBHXZ) referenced in function "public: __thiscall CryptoPP::Base64Decoder::Base64Decoder(class CryptoPP::BufferedTransformation *)" (??0Base64Decoder@CryptoPP@@QAE@PAVBufferedTransformation@1@@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2001	unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj	1	
Error	LNK2019	unresolved external symbol "bool __cdecl Base64Encode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Encode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "int __stdcall SaveLicenceCode(struct HWND__ *,unsigned int,unsigned int,long)" (?SaveLicenceCode@@YGHPAUHWND__@@IIJ@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\ResultSheets.obj	1	
Error	LNK2019	unresolved external symbol "bool __cdecl Base64Decode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Decode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "bool __cdecl IsValidLicence(void)" (?IsValidLicence@@YA_NXZ)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\LicenceFileData.obj	1	
Error	LNK2001	unresolved external symbol "bool __cdecl Base64Decode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Decode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)	ResultSheets	C:\Users\HP\source\repos\ResultSheets\ResultSheets.obj	1	
Error	LNK1120	11 unresolved externals	ResultSheets	C:\Users\HP\source\repos\ResultSheets\Debug\ResultSheets.exe	1	


What I have tried:

Google search did not yield any useful result. The talked of missing .cpp files for LNK2001, but I have the dynamic library in place.I see no reason why a .cpp file should still be relevant when dealing with a dll.
Posted
Updated 28-Jul-24 0:59am
v3
Comments
Dave Kreskowiak 28-Jul-24 12:33pm    
To answer your reply on your other question, CodeProject has nothing to do with other sites at all. Articles are written by people who volunteer their time, not by CodeProject staff. If someone links to an external site, like github or some crypto library, CodeProject has no relationship with those sites at all. No monitoring is done of those links, nor any fitness or accuracy guaranteed. If a link fails, it is not up to CodeProject to fix that link or site.

Frankly, I'm amazed you don't know this because it's standard practice across the entire web, not just CodeProject.
Gbenbam 28-Jul-24 12:39pm    
OK. Noted.
RedDk 28-Jul-24 15:35pm    
I'm looking at this collection of errors which you correctly identify as causing the linker to fail to output an executable ... but wait. The last LNK1120, although also "unresolved external", is not telling me that the output from the linker has failed, it's telling ne how many times the overall process has failed (1x). All those mangled function stubbs in all those messages, however, give me plenty of string to use to search through the contents of the folder that contains all the .lib files that MIGHT be used to get what you want from the linker withouit any fails. For instance, you could search for "AuthenticateLastFooterBlock" or you could search for "IsolatedInitialize" or you could search for SetKeyWithoutResync" ... any of those, if they're present in the .lib you're using should return an .lib in the results. I would use the .libs which show up in the result.

The whole process of chasing down a LNK unresolved external symbol is one o fthe first things that becomes old hat when programming in C++. It's a hit or miss situation which sometimes ends up shutting down your project because the third-party library is not what the vendor intended to make available. For whatever blue-padded-dashboard of a reason.
Gbenbam 3-Aug-24 17:52pm    
I am sorry this is coming a bit late. I will create a console program using the and make it available via google drive. I won't be able to make the actual project available,but the console project will fully mimic it.
Richard MacCutchan 30-Jul-24 6:15am    
This issue is related to how you are building your project, but you have not provided the key information. So please remove all the code samples from your question and replace with a copy of your .vcxproj file, and directory listings of the directories that you are including. It would also help to see the output from dumpbin -exports Cryptopp.lib.

1 solution

The Google messages are incorrerct. LNKXXXX messages are caused by the linker, and in your case they are telling you that you have either mis-spelled some part of the names of all the missing items, or more likely, you have not included the Crypto++ library into your project.

And given the number of questions you have posted I would have expected you to understand the fundamentals of building a C/C++ ;project by now.
 
Share this answer
 
v2
Comments
Gbenbam 28-Jul-24 12:44pm    
The names are the ones from the library. I did not coin them. I you read my question well,you will see when I took expected steps to include the crypto++ library in my project.Do kindly go through my answer and tell if the steps I took were not appropriate.
Richard MacCutchan 28-Jul-24 12:57pm    
Well obviously something is not correct as the linker cannot find the library file. But I cannot guess where you may have made a mistake. So go and check your project setup carefully and make sure that all the files you are referring to are in the right places, and you have spelled their names correctly.
Richard MacCutchan 28-Jul-24 13:00pm    
It does occur to me that you may be better using the official Microsoft cryptography offering: Cryptography API: Next Generation - Win32 apps | Microsoft Learn[^].
Gbenbam 4-Aug-24 6:18am    
Does Microsoft cryptography offer authenticated encryption. I would prefer Microsoft cryptography. Its just that I do not think it offers authenticated enryption.
Richard MacCutchan 4-Aug-24 6:55am    
What do you mean by "authenticated encryption"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900