Building and linking test code for Crypto++

2019-09-03 03:43发布

问题:

I'm trying to write some simple test code for the Crypto++ library for a project. I have yet to manage to get my own code to build though. It compiles fine, the problem comes in linking. I'm still pretty new to Visual Studios, but I'm using VS10. The errors I'm getting are:

1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const *,unsigned char const *,unsigned char *)const " (?ProcessAndXorBlock@Base@DES@CryptoPP@@UBEXPBE0PAE@Z)
1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::UncheckedSetKey(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?UncheckedSetKey@Base@DES@CryptoPP@@UAEXPBEIABVNameValuePairs@3@@Z)

I've tried everything I can find in the documentation in terms of linking. I've never linked against a DLL before, but these are the errors I get when I try to. If I try to do what I think is linking against the static library version, I get even more.

I should note, I'm trying to test pure DES at the moment. In particular, here are the API calls I'm making, just to be safe:

DES::Encryption  DES_encrypt;
DES_encrypt.SetKey(key, 64);
DES_encrypt.ProcessAndXorBlock(plaintext, NULL, ciphertext);

DES::Decryption DES_decrypt;
DES_decrypt.SetKey(key, 64);
DES_decrypt.ProcessAndXorBlock(ciphertext, NULL, decrypted);

If anyone can help, or point me in the right direction, I'd be much obliged.

回答1:

First thing to check is your project properties (right click on project, click Properties).

External libraries need to be specified in the Linker->Input->Additional Dependencies field, either by absolute path or in conjunction with the other VS path properties.

You can look in Linker->Command Line and check that the .lib files you want are actually being passed to the linker.

An alternate method is to turn off the Suppress Startup Banner option in the Linker->General options, and then check the build output to make sure it has what you want.

If you know that the libraries you want are being linked, another useful trick is to check the output of the strings command (in linux or cygwin) or dumpbin /HEADERS in the VS command prompt. You can look through the output of these commands for the symbol VS claims is missing to verify that it really is defined in the .lib file. Sometimes larger software packages have multiple .lib files, so this can help make sure you are linking the one that has the symbol you want.