Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No reference to BIO-functions when linking OpenSSL

I'm trying to compile a c-program with openssl-references. I'm using Linux Mint 17.1 and the development package "libssl-dev" is installed.

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

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

If I compile the code with:

gcc -o client bio-ssl-smtpcli2.c

I get the this error:

/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'

Does someone have an idea how to fix this?

like image 494
S1J0 Avatar asked May 09 '15 15:05

S1J0


1 Answers

I managed to compile your function by using :

gcc main.c -o main -I /usr/local/ssl/include -L /usr/local/ssl/lib -lssl -lcrypto -Wall

More explainations :

  • -I /usr/local/ssl/include adds /usr/local/ssl/include to the include search path.

  • -L /usr/local/ssl/lib adds /usr/local/ssl/lib to the library search path.

  • -lssl -lcrypto links libraries libcrypto and libssl

  • -lcrypto must follow -lssl becuase ld is a single pass linker

  • Wall enables all warnings.

My guess is that you are missing -lcrypto.

like image 60
francis Avatar answered Nov 13 '22 08:11

francis