C++ 如何用OpenSSL编译一个简单的程序?

C++ 如何用OpenSSL编译一个简单的程序?,c++,gcc,openssl,compilation,ld,C++,Gcc,Openssl,Compilation,Ld,我试图编译一个简单的ssl程序(它取自openssl书籍源代码)。 该程序有以下文件:common.h common.c client.c server.c 我已经安装了openssl 0.9.7,因此我的版本与本书相同。 我已经在主目录中下载了源代码和./Configure、make、make test、make install 在通用.h中,包括以下内容: #include <openssl/bio.h> #include <openssl/err.h> #inclu

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

我已经安装了openssl 0.9.7,因此我的版本与本书相同。 我已经在主目录中下载了源代码和./Configure、make、make test、make install

在通用.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-lcrypto-lssl

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书籍的某些代码版本中,线程相关函数存储在reentrant.c中(事实上,在我看到的版本中,TRHEAD_setup的声明就在这里),因此请尝试:

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

当你说
标题时,你的意思是
?如果你担心链接到哪个库,请使用-L选项指定显式路径。是的,你是对的!这为我解决了这个问题,尽管在我的版本中甚至没有提到reentrant.c。我从哪里获得reentrant.c文件?源代码在
gcc -Wall common.c client.c reentrant.c -o client -lcrypto -lssl