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

How to build Crypto++ 5.6.2 in for Qt with Visual Studio 2013?

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

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

archive of a pre-converted solution file, project files and filters for Visual Studio 2010 and above."

然后我:

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

但是在 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

你知道我为什么会收到这些错误吗?

任何 help/comment/insight 将不胜感激。

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(以及许多其他 classes)。

一般来说,您应该避免 FIPS DLL 除非您有硬性要求这样做。它的特殊用途,并且不容易使用。它还具有 FIPS 140-2 的 操作环境 要求。我怀疑您是否想将自己限制为 Visual Studio 2005 和 Windows Server 2003。

如果您坚持使用FIPS DLL,那么您需要link按预期对付DLL。 "As expected"表示你在compile/link次使用了cryptopp.lib导入库; cryptopp.dll 在 运行 时间。您还必须再次 link cryptlib.lib 以获取缺少的 classes,例如 ThreadUserTimer,同时设置 CRYPTOPP_IMPORTS 以避免在使用两个库时出现重复符号。


不使用 DLL,而是下载更新的(和修复的)vs2010-dynamic.zip。使用它构建 Crypto++ 库,然后使用静态库。 "Use the static library" 表示仅 link 对抗 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 composer 可以使用的东西。

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


vs2010.zip, vs2010-dynamic.zip and vs2005-dynamic.zip are built from the latest GitHub sources。在撰写本文时(2016 年 6 月 1 日),这实际上是 Crypto++ 5.6.4 之前的版本。如果您使用的 ZIP 文件具有较低级别的 Crypto++,例如 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 中可用的最新 classes。它们包括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 项目文件中删除缺少的源文件,因为它们在低级别版本中不存在。

另一种选择是从最新来源添加缺失的 class 文件,但这可能会很复杂。例如,许多来源巧妙地依赖于最新的 config.hcpu.hcpu.cpp。 "subtlety" 是你不会意识到你的表现不佳 class.

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