如何使用OpenSSL编译一个简单的程序
How to compile a simple program with OpenSSL?
我正在尝试编译一个简单的ssl程序(它取自openssl书的源代码)。该程序有以下文件:common.h common.c client.c server.c
我已经安装了openssl 0.9.7,所以我和这本书的版本相同。我已经下载了源代码和/在主目录中配置、制作、测试、安装。
在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客户端,但我得到以下错误:
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
显然,它无法链接到头文件。。。当我按照论坛中的建议运行时,我得到了
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
但是添加-lpthread无助于解决问题。。。
知道为什么会发生这种情况以及如何解决吗?
我的猜测是,lcrypto和lssl默认安装在ubuntu中,这样做-lcypto就是告诉链接器查看系统头,而不是openssl安装头。。。
任何帮助或建议都将不胜感激!
谢谢!
在openssl书的一些代码版本中,与线程相关的函数存储在retrent.c中(事实上,在我看到的版本中,TRHEAD_setup的声明就在那里),所以尝试使用:
gcc -Wall common.c client.c reentrant.c -o client -lcrypto -lssl
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- 为什么一个简单的程序不能立即启动
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- 为什么 MSVC C++编译器将一个简单的 Hello World 扩展为 4000 行汇编?
- 我写了一个简单的矢量程序,在其中我得到了以下输出。你能帮我理解它的输出吗?
- 如何使用 c++ 在命令行中创建一个简单的字符控制器?
- 对于 ~95% 写入/5% 读取线程安全的无序列图,有没有一个简单的解决方案?
- 在C++中创建一个简单的数据包路由器,如何跟踪"客户端"?
- 创建一个简单的前向迭代器,该迭代器在循环缓冲区的"end"处自动换行
- 我已经安装了用于c++编程的升华3,但在编写了一个简单的程序后,我遇到了以下错误
- 如何设置一个简单的CGAL+Qt程序
- 如何在一个简单的C++项目中使用Poco库
- 我创建了一个简单的程序,但有些地方不对劲
- Qt的新信号/时隙语法问题 - 连接到一个简单的函数
- 一个简单的 win32 多线程代码.这能行吗?
- 我正在尝试构建一个简单的程序来从 mysql 数据库中读取信息
- 创建一个简单的计算器,添加时遇到问题
- 我正在编写一个简单的客户端套接字应用程序,但在连接后服务器收到一个空缓冲区
- 为什么一个简单的"Hello World"风格的程序不能用Turbo C++编译?