简体   繁体   English

构建和链接Crypto ++的测试代码

[英]Building and linking test code for Crypto++

I'm trying to write some simple test code for the Crypto++ library for a project. 我正在尝试为项目的Crypto ++库编写一些简单的测试代码。 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. 我还是Visual Studios的新手,但是我使用的是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. 我以前从未链接过DLL,但是这些是我尝试连接时遇到的错误。 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. 我应该注意,目前我正在尝试测试纯DES。 In particular, here are the API calls I'm making, just to be safe: 特别是,为了安全起见,以下是我正在进行的API调用:

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. 如果有人可以提供帮助,或为我指明正确的方向,我将非常有义务。

First thing to check is your project properties (right click on project, click Properties ). 首先要检查的是您的项目属性(右键单击项目,单击“ 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. 外部库需要在Linker->Input->Additional Dependencies字段中通过绝对路径或与其他VS路径属性一起指定。

You can look in Linker->Command Line and check that the .lib files you want are actually being passed to the linker. 您可以在“链接器”- Linker->Command Line查看并检查所需的.lib文件是否已实际传递到链接器。

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. 另一种方法是关闭“链接器”- Linker->General选项中的“ Suppress Startup Banner选项,然后检查构建输出以确保它具有所需的内容。

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. 如果知道要链接的库,另一个有用的技巧是在VS命令提示符dumpbin /HEADERS检查strings命令(在linux或cygwin中)或dumpbin /HEADERS的输出。 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. 您可以查看这些命令的输出,以查找缺少VS声明的符号,以验证它是否确实在.lib文件中定义。 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. 有时,较大的软件包包含多个.lib文件,因此这有助于确保您链接的是具有所需符号的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM