设置加密++

Setting up crypto++

我下载了 crypto++ 5.6.2(zip 文件)并仅使用 make 构建了它(我有 gcc 4.8.1)。它似乎有效并给了我一个 libcryptopp.a 文件。

现在,为了测试设置,我尝试编译随下载提供的 test.cpp 文件(link 此处:http://www.cryptopp.com/docs/ref/test_8cpp_source.html)。

首先,我用

编译了它

g++ -Wall -std=c++11 -g -Iinclude -I/c/libraries/cryptopp562 -c test.cpp -o obj/test.o

它给出了很多警告(主要是弃用和未使用的变量)但有效并且我得到了 test.o 文件。

现在,为了link它,我用了

g++ obj/test.o -o bin/test -L/c/libraries/cryptopp562 -lcryptopp

但这给出了很多 undefined reference 错误并且失败了。

例如

D:\.../test.cpp:119: undefined reference to `RegisterFactories()'

但是当你查看test.cpp文件(http://www.cryptopp.com/docs/ref/test_8cpp_source.html)时,只有对RegisterFactories()的声明,而没有定义。这是否意味着它需要从库中找到它? (在这种情况下不需要本地声明,不是吗?)

好的,那么我需要做什么才能让整个库正常工作?使用gmake来构建它?或者使用更旧的 gcc?或者我的 compile/link 命令不正确?

test.cpp 不是独立的。它使用了很多其他文件。实际上它已经在构建中使用了(参见 GNUmakefile)。构建完成后,会生成 libcryptopp.a 和 cryptest.exe。 test.cpp 用于构建 cryptest.exe。

你提到的具体函数定义在regtest.cpp中。它还使用了其他 C++ 文件中的许多其他函数。

Setting up crypto++

在 Linux 下设置 Crypto++ 的说明位于 Build and Install the Library 的 wiki 上。


... to test the setup, I tried to compile the test.cpp ...

如果你想构建测试套件,那么你 运行 make cryptest.exe.

如果你想运行构建测试套件,你运行 ./cryptest.exe v


undefined reference to RegisterFactories()

测试套件中使用了 9 个源文件。他们是:

  • validate.h、bench.h
  • test.cpp,数据test.cpp
  • bench.cpp, bench2.cpp
  • validat1.cpp、validat2.cpp、validat3.cpp

... what do I have to do to get the whole library to work?

make cryptest.exe./cryptest.exe v 通常工作正常:)

我通常运行 make static dynamic cryptest.exe 构建静态存档和共享对象。

您也可以运行使用tv命令单独测试。例如,./cryptest.exe tv sha1 将 运行 SHA-1 相关测试。 tv 是 "test vectors",它们位于源代码的“TestVectors”目录中。


相关,如果你想让测试套件在安装后运行,那么你需要DataDir Patch.

这是社区提供的补丁。它不是 Crypto++ 库的一部分(尽管它可能应该是库的一部分)。