如何使用Visual Studio 2013为Qt构建Crypto ++ 5.6.2?

时间:2016-05-27 16:41:15

标签: qt dll crypto++

我正在尝试使用Visual Studio 2013为Qt构建Crypto ++ 5.6.2,但它产生错误。这是我到目前为止所做的。

页面上显示的是vs2010-dynamic.zip,但ZIP仅包含cryptest.sln的VS2005。只是一个文件。但无论如何,我使用了文件:

  

Visual Studio 2010及更高版本的预转换解决方案文件,项目文件和过滤器的存档。"

然后我:

  • 在MSVC2013中打开cryptest.sln,并设置"多线程DLL(/ MD)"对于每个项目(项目 - >属性 - > C / C ++ - >代码生成 - >运行时库 - > / MD)

  • 构建 - > '批量构建' - >检查cryptdll,cryptest,cryptlib,dlltest(发布| win32) - >构建

它在DLL_Output目录中生成了DLL和LIB。然后我:

  • 将DLL移动到Qt可执行文件所在的目录。
  • 在Qt中,我向test.pro添加了两行:
    • INCLUDEPATH += "../extern/msvc2013/cryptopp562/include"
    • LIBS += -L"..\extern\msvc2013\cryptopp562\include\cryptopp\Win32\DLL_Output\Release" -lcryptopp

但是在Qt中,我遇到了以下错误:

mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::GetCurrentTimerValue(void)" (?GetCurrentTimerValue@ThreadUserTimer@CryptoPP@@UAE_KXZ)

mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::TicksPerSecond(void)" (?TicksPerSecond@ThreadUserTimer@CryptoPP@@UAE_KXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class CryptoPP::NameValuePairs const & const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs@CryptoPP@@3ABVNameValuePairs@1@B) referenced in function "public: __thiscall CryptoPP::HMAC::HMAC(unsigned char const *,unsigned int)" (??0?$HMAC@VSHA256@CryptoPP@@@CryptoPP@@QAE@PBEI@Z)

release\user_account_registration.exe:-1: error: LNK1120: 3 unresolved externals

您对我收到错误有什么想法吗?

非常感谢任何帮助/评论/见解。

1 个答案:

答案 0 :(得分:0)

mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::GetCurrentTimerValue(void)" (?GetCurrentTimerValue@ThreadUserTimer@CryptoPP@@UAE_KXZ)

mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: virtual unsigned __int64 __thiscall CryptoPP::ThreadUserTimer::TicksPerSecond(void)" (?TicksPerSecond@ThreadUserTimer@CryptoPP@@UAE_KXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class CryptoPP::NameValuePairs const & const CryptoPP::g_nullNameValuePairs" (?g_nullNameValuePairs@CryptoPP@@3ABVNameValuePairs@1@B) referenced in function "public: __thiscall CryptoPP::HMAC::HMAC(unsigned char const *,unsigned int)" (??0?$HMAC@VSHA256@CryptoPP@@@CryptoPP@@QAE@PBEI@Z)

如果查看hrtimer.h的源代码,则ThreadUserTimer缺少CRYPTOPP_DLL。这意味着DLL不会导出ThreadUserTimer(以及许多其他类)。

一般情况下,除非您有严格的要求,否则应避免使用FIPS DLL。它的特殊用途,并不容易使用。它还具有FIPS 140-2的操作环境要求。我怀疑你是否想限制自己使用Visual Studio 2005和Windows Server 2003。

如果您坚持使用FIPS DLL,则需要按预期链接DLL。 "正如所料"意味着您在编译/链接时使用cryptopp.lib导入库;和cryptopp.dll在运行时。您还必须再次链接cryptlib.lib以获取缺少的类,例如ThreadUserTimer,同时设置CRYPTOPP_IMPORTS以避免在使用这两个库时出现重复的符号。

不要使用DLL,而是下载更新的(和修复的)vs2010-dynamic.zip。使用它来构建Crypto ++库,然后使用静态库。 "使用静态库"表示仅与cryptlib.lib链接。

来自vs2010-dynamic.zip的项目文件可能会引用一些您不具备的源文件,因为它是从最新的稳定源构建的。如果缺少源文件,则只需将其从项目文件中删除即可。在我的头脑中,Crypto ++ 5.6.2应该缺少HKDF,RDRAND,RDSEED,ChaCha,BLAKE2,Base64URLEncoder,Base64URLDecoder等。它还缺少bench.cppbench1.cpp的重命名。

Visual Studio wiki页面提供了有关Windows项目文件和工件(如cryptlib.lib)的更多信息。

INCLUDEPATH += ".../cryptopp562/include"
LIBS += -L"...\cryptopp562\include\cryptopp\Win32\DLL_Output\Release" -lcryptopp

我认为你应该只使用 -lcryptlib,因为它是静态库,它拥有你需要的一切。图书馆的路径是$(Platform)\Output\$(Configuration),但我不知道如何将其翻译成QT作曲家可以使用的内容。

否则,我认为您需要同时指定-lcryptopp -lcryptlib,并将CRYPTOPP_IMPORTS添加到预处理器定义。

vs2010.zipvs2010-dynamic.zipvs2005-dynamic.zip是根据latest GitHub sources构建的。在撰写本文时(2016年6月1日),这有效地预先加密了++ 5.6.4。如果您使用的是具有低级Crypto ++的ZIP文件,例如5.6.2或5.6.3,那么您将遇到小问题。

我知道有两个小问题。首先是bench.cpp to bench1.cpp的重命名。它的错误是:

  • C1083: Cannot open source file: 'bench1.cpp': No such file or directory
  • LNK2001: unresolved external symbol "void __cdecl OutputResultOperations(char const *,char const *,bool,unsigned long,double)" (?OutputResultOperations@@YAXPBD0_NKN@Z)

修复方法是(1)在记事本中打开cryptest.vcxproj,找到bench1.cpp,然后将其重命名为bench.cpp。或者(2)在文件系统上将bench.cpp重命名为bench1.cpp

第二个问题有点棘手,因为它是一个移动的目标。低级版本(如5.6.2或5.6.3)缺少GitHub中提供的最新类。它们包括HKDF(5.6.3),RDRAND(5.6.3),RDSEED(5.6.3),ChaCha(5.6.4),BLAKE2(5.6.4),Poly1305(5.6.4)等。

修复方法是从Visual Studio项目文件中删除缺少的源文件,因为它们不适用于下层版本。

另一种选择是从最新的来源添加缺少的类文件,但可能会有并发症。例如,许多来源巧妙地依赖于最新的config.hcpu.hcpu.cpp。 "微妙"你是否意识到自己的表现不佳。

表现不佳的一个例子是BLAKE2。 config.h增加了编译时间ARM-32和ARM-64检测。 cpu.hcpu.cpp添加了运行时ARM指令检测。如果在没有其他文件的情况下添加BLAKE2,则不会发生任何检测,并且您将获得直接的C / C ++实现。 NEON实现每字节运行大约9到12个周期,而C / C ++实现每个字节运行大约40个周期。