链接OpenSSL时未引用BIO函数

S1J*_*1J0 4 c linux ssl openssl compilation

我正在尝试使用openssl-references编译C程序。我正在使用Linux Mint 17.1,并且已安装开发包“ libssl-dev”。

#include <openssl/bio.h>
#include <openssl/err.h>
#include &lt;openssl/ssl.h>
...

void send_smtp_request(BIO *bio, const char *req)
{
    BIO_puts(bio, req);
    BIO_flush(bio);
    printf("%s", req);     
}
Run Code Online (Sandbox Code Playgroud)

如果我用以下代码编译代码:

gcc -o client bio-ssl-smtpcli2.c
Run Code Online (Sandbox Code Playgroud)

我得到这个错误:

/tmp/ccCHrti2.o: In function 'send_smtp_request':
bio-ssl-smtpcli2.c:(.text+0x1f):  undefined reference to 'BIO_puts'
bio-ssl-smtpcli2.c:(.text+0x3a):  undefined reference to 'BIO_ctrl'
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决此问题?

fra*_*cis 6

我设法通过使用来编译您的函数:

gcc main.c -o main -I /usr/local/ssl/include -L /usr/local/ssl/lib -lssl -lcrypto -Wall
Run Code Online (Sandbox Code Playgroud)

更多说明:

  • -I /usr/local/ssl/include添加/usr/local/ssl/include到包含搜索路径。

  • -L /usr/local/ssl/lib添加/usr/local/ssl/lib到库搜索路径。

  • -lssl -lcrypto 链接库libcrypto和libssl

  • -lcrypto必须遵循,-lssl因为ld是单通链接器

  • Wall 启用所有警告。

我的猜测是你失踪了-lcrypto