对 'SHA1' 的未定义引用
Undefined reference to 'SHA1'
我在windows中使用Bloodshed DevC++ 7.我使用DEV中的包安装功能安装了OpenSSL库包。
我从一个简单的 C 代码开始寻找 SHA。我确定库连接正确。但出于某种奇怪的原因,我收到链接器错误,即 [linker error] Undefined reference to 'SHA1'
我看过包括 SOF 在内的其他网站,但我无法找出问题的根源。我在 SOF 上看到过各种解决此问题的帖子,但没有评论解决我遇到的问题。任何帮助将不胜感激。我看到有人说你需要使用 -lcrypto 但我很困惑他们指的是什么。
[编辑]
我给出代码如下:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int main ()
{
unsigned char ibuf[] = "compute sha1";
unsigned char obuf[20];
SHA1(ibuf,strlen(ibuf),obuf);
int i=0;
for (i = 0; i < 20; i++)
{
printf("%02x ", obuf[i]);
}
printf("\n");
getch();
}
在项目选项中,在 Parameters
选项卡中有三个选项框,一个指定 C compiler
,第二个指定 C++ Compiler
,第三个指定 Linker
。
在 Linker
框中,您需要添加 -lcrypto
并重建您的项目。
这是特定于 Dev-C++ 开发环境的,但重复了人们在评论中告诉您的内容。
I presume you're using the Dev-C++ v5.11 version as the last one available on the bloodshed website is a beta and doesn't work on my system, which is Win 10.
感谢所有为解决问题做出贡献和协助的人。特别感谢 Petesh 教授 ;) 如果没有他的帮助,我又要浪费一个星期了。
我会提供详细信息如下:
首先下载最新的DEVC++最好是5.11。确保您使用正确的 32/64 位版本的编译器,否则您将遇到 linking/构建错误。
-lcrypto 和其他库需要通过项目选项->参数->链接器添加到项目中。可以通过
添加文件
使用添加库或对象按钮。
确保包含目录包含 link 到 openssl
文件夹。在我的系统中,路径是“C:\Program Files
(x86)\Dev-Cpp\include"
我在windows中使用Bloodshed DevC++ 7.我使用DEV中的包安装功能安装了OpenSSL库包。
我从一个简单的 C 代码开始寻找 SHA。我确定库连接正确。但出于某种奇怪的原因,我收到链接器错误,即 [linker error] Undefined reference to 'SHA1'
我看过包括 SOF 在内的其他网站,但我无法找出问题的根源。我在 SOF 上看到过各种解决此问题的帖子,但没有评论解决我遇到的问题。任何帮助将不胜感激。我看到有人说你需要使用 -lcrypto 但我很困惑他们指的是什么。
[编辑]
我给出代码如下:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int main ()
{
unsigned char ibuf[] = "compute sha1";
unsigned char obuf[20];
SHA1(ibuf,strlen(ibuf),obuf);
int i=0;
for (i = 0; i < 20; i++)
{
printf("%02x ", obuf[i]);
}
printf("\n");
getch();
}
在项目选项中,在 Parameters
选项卡中有三个选项框,一个指定 C compiler
,第二个指定 C++ Compiler
,第三个指定 Linker
。
在 Linker
框中,您需要添加 -lcrypto
并重建您的项目。
这是特定于 Dev-C++ 开发环境的,但重复了人们在评论中告诉您的内容。
I presume you're using the Dev-C++ v5.11 version as the last one available on the bloodshed website is a beta and doesn't work on my system, which is Win 10.
感谢所有为解决问题做出贡献和协助的人。特别感谢 Petesh 教授 ;) 如果没有他的帮助,我又要浪费一个星期了。
我会提供详细信息如下:
首先下载最新的DEVC++最好是5.11。确保您使用正确的 32/64 位版本的编译器,否则您将遇到 linking/构建错误。
-lcrypto 和其他库需要通过项目选项->参数->链接器添加到项目中。可以通过
添加文件 使用添加库或对象按钮。确保包含目录包含 link 到 openssl
文件夹。在我的系统中,路径是“C:\Program Files
(x86)\Dev-Cpp\include"