Cryptopp在Visual Studio中动态链接发生Link2001错误

错误发生

首先我用的是Visual Studio 2022学生版,在官网上下载了870版本的cryptopp。之后对cryptlib方案进行生成,得到了Debug和Release模式下的静态链接库。然后用静态链接的方式可以正常运行程序。由于一些原因,我需要使用动态链接库,所以我又生成了dll文件和lib文件。
在这里插入图片描述

// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#pragma comment(lib,"D:\\File\\VSWorkspace\\TestRC6\\Project1\\Project1\\lib\\cryptopp.lib")
#include <cryptopp/rc6.h>
#include <cryptopp/eax.h>
#include<cryptopp/filters.h>
#include<cryptopp/hex.h>
#include <iostream>
#include<string.h>
using namespace  std;
using  namespace CryptoPP;

int main()
{
    string plain = "4";
    string cipher, encoded;
    SecByteBlock key(RC6::DEFAULT_KEYLENGTH);
    byte iv[RC6::BLOCKSIZE];
    cout << "plain text:" << plain << endl;
    CTR_Mode<RC6>::Encryption e;
    e.SetKeyWithIV(key, key.size(), iv);
    StringSource s1(plain, true, new StreamTransformationFilter(e, new StringSink(cipher)));
    StringSource s2(cipher, true, new HexEncoder(new StringSink(encoded)));
    cout << "cipher text:" << encoded << endl;
    return 0;
}

但是发生了以下错误,期间用了很多方法都没办法解决。
在这里插入图片描述
我把生成的dll文件和lib文件放在了lib文件夹,然后dll文件放在了项目的工作目录,但是还是不行。我能保证 属性》C/C++》代码生成》运行库是与配置(Debug还是Release)是一致的。
在这里插入图片描述

问题解决

之后我翻阅了cryptopp官方的文档,发现只有某些算法支持动态链接的方式。
在这里插入图片描述
需要在所有cryptopp的include前加上#include "cryptopp/dll.h",并且不需要加#pragma comment(lib, "cryptopp")来声明链接库,因为dll.h中声明过了。这个方法测试之后我发现,会发生其他错误Cryptographic algorithms are disabled after a power-up self test failed
在翻阅cryptopp官方文献后得出结论,cryptopp不建议输出动态库,如果需要输出动态库是需要自己去包装dll。

后续

我的问题已经解决了,之前我需要在HEVC的测试模型HM上使用cryptopp。然后在我生成HM的解决方案TApp时,需要用到一些库。但是我把所需的库用***多线程调试DLL (/MDd)的方式输出,而对解决方案TApp采用多线程调试 (/MTd)的方式输出,这导致一些符号产生重复定义。之后我把所需的库用多线程调试 (/MTd)***的方式输出,并把cryptopp进行静态链接。问题解决了。

[1].cryptopp关于dll的解释
[2].包装dll

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值