请帮助 - 如何在我的代码中包含OpenSSL? [英] PLEASE HELP - How do I include OpenSSL in my code?

查看:53
本文介绍了请帮助 - 如何在我的代码中包含OpenSSL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些C大师可以帮帮我吗?我有一段简单的代码:


#include< stdio.h>

#include< stdlib.h>

#include< openssl / rand.h>


int main(){

unsigned char temp [4];


RAND_bytes(临时,4);

返回0;

}


如果我输入: where openssl

我得到:openssl:/ usr / bin / openssl / usr / include / openssl

/usr/share/man/man1/openssl.1ssl.gz


我将其编译为:

gcc -g -o test test.c -I / usr / include / openssl -L / usr / bin / openssl


我收到一条链接器错误消息:

/tmp/cc4tQEqd.o(.text+0x1af0):在函数main中:

/home/ecelrc/students/abanerj/cpp/test.c:6:undefined reference to

`RAND_bytes''


可以有人请指出我做错了什么?任何帮助都会很好

赞赏。

解决方案

cp ********** @ yahoo.com 说:

我收到一条链接器错误消息:
/tmp/cc4tQEqd.o(.text+0x1af0):在函数main中:
/ home / ecelrc / students / abanerj / cpp / test.c:6:未定义引用
`RAND_bytes''




您忘记将-lssl添加到gcc行的末尾。


严格地说,第三方库在clc中是偏离主题的 - 但是,嘿,我不会告诉你b $ b告诉你是不是。 />

下一次,尝试一个Linux组,只是为了安全起见。在这里,如果它不是ANSI,我们会得到所有

antsy。 :-)


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)


cp ********** @ yahoo.com 写道:

可能有些C大师请帮助我?我有一段简单的代码:

#include< stdio.h>
#include< stdlib.h>
#include< openssl / rand.h> ;


你想让我们陷入困境,不是吗?即使openssl在这里的主题是

,或者你的实现特定问题是关于

主题,openssl网站上的语言会让我失望:请记住这个出口/导入和/或使用强大的密码学软件,提供密码书或即使只是交流
关于密码软件的技术细节在世界某些部分是非法的。因此,当您将此包装进口到您的国家/地区时,或者从那里重新分发它或者只是发送电子邮件技术建议
或者甚至会向作者或其他人员提供补救措施
建议您谨慎关注任何出口/进口和/或使用法律
适用于您。 OPENSSL的作者对您在此处所做的任何违规行为不承担任何责任。非常小心,这是你的责任。



在2006-05-12, cp ********** @ yahoo.com < cp ********** @ yahoo.com>写道:

有些C大师可以帮帮我吗?我有一段简单的代码:

#include< stdio.h>
#include< stdlib.h>
#include< openssl / rand.h> ;

int main(){
unsigned char temp [4];

RAND_bytes(temp,4);
返回0;
}

如果我输入:whereis openssl
我得到:openssl:/ usr / bin / openssl / usr / include / openssl
/ usr / share / man / man1 / openssl.1ssl.gz

我将其编译为:
gcc -g -o test test.c -I / usr / include / openssl -L / usr / bin / openssl
我收到一条链接器错误消息:
/tmp/cc4tQEqd.o(.text+0x1af0):在函数main中:
/ home / ecelrc / students / abanerj / cpp / test.c:6:未定义引用
`RAND_bytes''

有人可以指出我做错了吗?任何帮助都会非常感激。




你需要-l。


-L告诉gcc在哪里查找库,-l告诉它要用什么库来查找符号。


-lxxx表示查找一个名为库的库 libxxx.a在通常的地方。

如果需要,你可以用-L将地点添加到通常的地方。


图书馆你想要的是libssl.a并且很可能在/ usr / lib中,无论如何

gcc看起来如此,所以没有-L选项的-lssl可能会做到这一点:


Could some C guru please help me? I have a simple piece of code as:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/rand.h>

int main(){
unsigned char temp[4];

RAND_bytes(temp, 4);
return 0;
}

If I type: whereis openssl
I get: openssl: /usr/bin/openssl /usr/include/openssl
/usr/share/man/man1/openssl.1ssl.gz

I compile this as:
gcc -g -o test test.c -I/usr/include/openssl -L/usr/bin/openssl

I get a linker error message as :
/tmp/cc4tQEqd.o(.text+0x1af0): In function `main'':
/home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
`RAND_bytes''

Could someone please point out what I am doing wrong? Any help would be
greatly
appreciated.

解决方案

cp**********@yahoo.com said:

I get a linker error message as :
/tmp/cc4tQEqd.o(.text+0x1af0): In function `main'':
/home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
`RAND_bytes''



You forgot to add -lssl to the end of your gcc line.

Strictly speaking, third party libs are off-topic in clc - but hey, I won''t
tell if you don''t.

Next time, though, try a Linux group, just to play safe. Here, we get all
antsy if it ain''t ANSI. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


cp**********@yahoo.com wrote:

Could some C guru please help me? I have a simple piece of code as:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/rand.h>
You''re trying to get us into trouble, aren''t you. Even if openssl were
on topic here, or if your implementation-specific question were on
topic, the language from the openssl site would scre me off: PLEASE REMEMBER THAT EXPORT/IMPORT AND/OR USE OF STRONG CRYPTOGRAPHY
SOFTWARE, PROVIDING CRYPTOGRAPHY HOOKS OR EVEN JUST COMMUNICATING
TECHNICAL DETAILS ABOUT CRYPTOGRAPHY SOFTWARE IS ILLEGAL IN SOME
PARTS OF THE WORLD. SO, WHEN YOU IMPORT THIS PACKAGE TO YOUR COUNTRY,
RE-DISTRIBUTE IT FROM THERE OR EVEN JUST EMAIL TECHNICAL SUGGESTIONS
OR EVEN SOURCE PATCHES TO THE AUTHOR OR OTHER PEOPLE YOU ARE STRONGLY
ADVISED TO PAY CLOSE ATTENTION TO ANY EXPORT/IMPORT AND/OR USE LAWS
WHICH APPLY TO YOU. THE AUTHORS OF OPENSSL ARE NOT LIABLE FOR ANY
VIOLATIONS YOU MAKE HERE. SO BE CAREFUL, IT IS YOUR RESPONSIBILITY.



On 2006-05-12, cp**********@yahoo.com <cp**********@yahoo.com> wrote:

Could some C guru please help me? I have a simple piece of code as:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/rand.h>

int main(){
unsigned char temp[4];

RAND_bytes(temp, 4);
return 0;
}

If I type: whereis openssl
I get: openssl: /usr/bin/openssl /usr/include/openssl
/usr/share/man/man1/openssl.1ssl.gz

I compile this as:
gcc -g -o test test.c -I/usr/include/openssl -L/usr/bin/openssl

I get a linker error message as :
/tmp/cc4tQEqd.o(.text+0x1af0): In function `main'':
/home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
`RAND_bytes''

Could someone please point out what I am doing wrong? Any help would be
greatly
appreciated.



You need -l.

-L tells gcc where to look for libraries, -l tells it what libraries to
look in for symbols.

-lxxx means "look for a library called libxxx.a in the usual places".
You add places to "the usual places", if necessary, with -L.

The library you want is libssl.a and is quite likely in /usr/lib, where
gcc looks anyway, so -lssl with no -L option will probably do the trick:


这篇关于请帮助 - 如何在我的代码中包含OpenSSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆