Openssl如何编译一个简单的程序? [英] Openssl how to compile a simple program?

查看:765
本文介绍了Openssl如何编译一个简单的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一个简单的ssl程序(它是从openssl书源代码)。
程序有以下文件:common.h common.c client.c server.c



我安装了openssl 0.9.7,所以我有同样的版本的书。
我已经下载了源代码和./Configure,make,make测试,在主目录中进行安装。



在common.h中有以下包括:

  #include< openssl / bio.h> 
#include< openssl / err.h>
#include< openssl / rand.h>
#include< openssl / ssl.h>
#include< openssl / x509v3.h>

我运行 gcc -Wall common.c client.c -o client 但我得到以下错误:

  common.c:在函数'init_OpenSSL':
common.c:12 :5:warning:隐式声明函数'THREAD_setup'
/tmp/ccvI3HX4.o:在函数`handle_error'中:
common.c :(。+ 0x3a):未定义引用`ERR_print_errors_fp'
/tmp/ccvI3HX4.o:在函数`init_OpenSSL'中:
common.c :(。+ 0x51):未定义引用`THREAD_setup'
common.c :(。
/tmp/ccRA0Co9.o:在函数`do_client_loop'中:
client.c :(。text + 0x71):未定义引用`BIO_write'
/tmp/ccRA0Co9.o:在函数`main'中:
client.c :(。text + 0xbb)未定义引用`BIO_new_connect'
client.c :( .text + 0x106):未定义引用`BIO_ctrl'
client.c :(。text + 0x18e):未定义引用`BIO_free'
collect2:ld返回1退出状态

显然它不能链接到头文件...
当我在一个论坛中建议运行 gcc -Wall common.c client.c -o client -lcrypto -lssl 时,我获得

  common.c:在函数'init_OpenSSL'中:
common.c:12:5:warning:隐式声明函数'THREAD_setup'
/ tmp / cc2gjx8W。 o:在函数`init_OpenSSL'中:
common.c :(。text + 0x51):未定义引用`THREAD_setup'
collect2:ld返回1退出状态



但是添加-lpthread不会帮助解决问题...



为什么会发生和如何解决呢?



我的猜测是lcrypto和lssl是默认安装在Ubuntu中,通过执行-lcypto告诉链接器来查看系统头文件,而不是openssl安装文件...



感谢任何帮助或指针!



谢谢

解决方案

在openssl书的一些代码版本中,线程相关函数存储在reentrant.c中,的TRHEAD_setup,在我看到的版本中有),所以尝试:

  gcc -Wall common.c客户端。 c reentrant.c -o client -lcrypto -lssl 


I am trying to compile a simple ssl program (it was taken from the openssl book source code). The program has the following files: common.h common.c client.c server.c

I have installed openssl 0.9.7 so I have the same version with the book. I have downloaded the source and ./Configure, make, make test, make install in the home directory.

In the common.h there are the following includes:

#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h> 

I run gcc -Wall common.c client.c -o client but I get the following errors:

common.c: In function ‘init_OpenSSL’:
common.c:12:5: warning: implicit declaration of function ‘THREAD_setup’
/tmp/ccvI3HX4.o: In function `handle_error':
common.c:(.text+0x3a): undefined reference to `ERR_print_errors_fp'
/tmp/ccvI3HX4.o: In function `init_OpenSSL':
common.c:(.text+0x51): undefined reference to `THREAD_setup'
common.c:(.text+0x5a): undefined reference to `SSL_library_init'
common.c:(.text+0x97): undefined reference to `SSL_load_error_strings'
/tmp/ccRA0Co9.o: In function `do_client_loop':
client.c:(.text+0x71): undefined reference to `BIO_write'
/tmp/ccRA0Co9.o: In function `main':
client.c:(.text+0xbb): undefined reference to `BIO_new_connect'
client.c:(.text+0x106): undefined reference to `BIO_ctrl'
client.c:(.text+0x18e): undefined reference to `BIO_free'
collect2: ld returned 1 exit status

Obviously it cannot link to the header files... When I run as suggested in one forum gcc -Wall common.c client.c -o client -lcrypto -lssl I get

common.c: In function ‘init_OpenSSL’:
common.c:12:5: warning: implicit declaration of function ‘THREAD_setup’
/tmp/cc2gjx8W.o: In function `init_OpenSSL':
common.c:(.text+0x51): undefined reference to `THREAD_setup'
collect2: ld returned 1 exit status

But adding -lpthread won't help resolve the problem...

Any idea why this happens and how to solve it?

My guess is that lcrypto and lssl are installed by default in ubuntu and by doing -lcypto is telling the linker to look at the systems headers and not the openssl installation ones...

Any help or pointers is appreciated!

Thank you!

解决方案

In some code versions of openssl book, the thread related functions are stored in reentrant.c, (in fact the declaration of TRHEAD_setup, in the version i've seen is there), so try with:

gcc -Wall common.c client.c reentrant.c -o client -lcrypto -lssl

这篇关于Openssl如何编译一个简单的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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