Openssl Sha1 编译问题
Openssl Sha1 compile issue
#include <algorithm>
#include <stdio.h>
#include <openssl/sha.h>
using namespace std;
int main()
{
unsigned char ibuf[] = "compute sha1";
unsigned char obuf[20];
SHA1(ibuf, strlen(ibuf), obuf);
int i;
for (i = 0; i < 20; i++) {
printf("%02x ", obuf[i]);
}
printf("n");
}
g++ file.cpp -o file -l libssl
file.cpp: In function ‘int main()’:
file.cpp:29:27: error: invalid conversion from ‘unsigned char*’ to ‘const char*’ [-fpermissive]
/usr/include/string.h:399:15: error: initializing argument 1 of ‘size_t strlen(const char*)’ [-fpermissive]
想知道怎么了..我正在尝试计算 sha1
首先,我想知道它是否在匿名化中丢失了,但在我看来缺少
include <string.h>
命令行应该看起来更像:
g++ file.cpp -o file -lssl
您正在使用C++编译器。C++编译器通常对类型非常严格。您已经定义了要unsigned char
ibuf
(并且在 strlen 中使用时它被视为 unsigned char *
(,并且strlen
期望const char*
,因此会产生错误。
您有以下选择:
您可以在
strlen
中投ibuf
:SHA1(ibuf, strlen((const char *)ibuf), obuf);
您可以使用建议的
-fpermissive
标志使g++
更加宽容,并将错误转换为纯粹的警告,尽管我不建议这样做:g++ -fpermissive file.cpp -o file -lssl
由于代码看起来就像一个普通的
C
,也许你不需要C++
编译器。如果是这种情况,只需使用 C 编译器而不是C++
:gcc file.cpp -o file -lssl
然后,您需要删除
include <algorithm>
并namespace..
。
相关文章:
- 编译包含字符串的代码时遇到问题
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 如何在 Mac 上正确编译C++,当它在 Linux 上编译没有问题时?
- Rextester 语言编译C++问题
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 编译 llvm 插件时出现问题:llvm/Config/llvm-config.h:没有这样的文件或目录
- C++ 多级虚拟继承编译问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- Qt Visual Studio 2015 加载项编译问题
- 构造函数和 G++ 编译配方的问题
- 解析问题 - 预期的非限定 ID - #include <array> 编译错误
- libssh 问题编译问题未定义的错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- Visual Studio 2017问题编译了C 代码,而该代码则在Linux中编译
- 这个C++代码有什么问题?编译错误:调用“测试::测试(测试)”没有匹配函数
- 试图编译基本Boost PropertyTree示例时出现问题-编译错误.该怎么做
- 如何解决***缺少分隔符的问题.编译QT(或支持库)时