c++ - 设置加密++

标签 c++ c++11 gcc crypto++

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

现在,为了测试设置,我尝试编译随下载提供的 test.cpp 文件(此处链接: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 文件。

现在,为了链接它,我使用了

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

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

例如

D:\.../test.cpp:119: 未定义对 `RegisterFactories()' 的引用

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

好的,那么我需要做什么才能让整个库正常工作?使用 gmake 构建它?或者使用旧的 gcc?或者也许我的编译/链接命令不正确?

最佳答案

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 个源文件。它们是:

  • 验证.h,bench.h
  • 测试.cpp、数据测试.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 是“测试 vector ”,它们位于源代码的“TestVectors”目录中。


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

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

关于c++ - 设置加密++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30412236/

相关文章:

c++ - 如何将命令行工具包装到应用程序中并正确退出?

c++ - Qt 堆碎片 - QObjects 可以放在内存池中吗?

c++ - strtok 和 atof 内存泄漏

c++ - 为什么不完整类型的智能指针数据成员和原始指针数据成员在其父级析构时具有不同的行为?

c++ - ‘internalPath’(类型 ‘std::string {aka std::basic_string<char>}’ )到类型 ‘std::basic_string<char>&&’

c++ - 自定义双向迭代器的 reverse_iterator 上的 for_each 需要 OutputIterator

c++ - 可以将自旋锁与 O(1) 非内存连续代码一起使用吗?

c++ - 错误 : 'strstr' was not declared in this scope

c - 使用 arm-gcc 3.3.1 在 32 位 pic 上循环

c++ - 从内存中加载动态库