Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Open SSL Dependent C Program with GCC

Tags:

c

linux

gcc

I have to compile a C program on linux(ubuntu) with gcc. Which is dependent to openssl libraries.

#include <openssl/crypto.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/err.h>

I've downloaded libcrypto and libopenssl package from repository. But still I'm getting this error

root@kali:~/openssl# gcc opensslhello.c 
/tmp/ccTahV7g.o: In function `pem2X509':
opensslhello.c:(.text+0x15): undefined reference to `BIO_s_mem'
opensslhello.c:(.text+0x1d): undefined reference to `BIO_new'
opensslhello.c:(.text+0x4e): undefined reference to `BIO_write'
opensslhello.c:(.text+0x71): undefined reference to `PEM_read_bio_X509'
opensslhello.c:(.text+0x7f): undefined reference to `BIO_free'
/tmp/ccTahV7g.o: In function `sendHelloFunction':
opensslhello.c:(.text+0xb9): undefined reference to `X509_STORE_new'
opensslhello.c:(.text+0xe2): undefined reference to `X509_STORE_add_cert'
opensslhello.c:(.text+0x106): undefined reference to `X509_STORE_add_cert'
opensslhello.c:(.text+0x113): undefined reference to `sk_new_null'
opensslhello.c:(.text+0x13c): undefined reference to `sk_push'
opensslhello.c:(.text+0x160): undefined reference to `sk_push'
opensslhello.c:(.text+0x187): undefined reference to `X509_STORE_CTX_new'
opensslhello.c:(.text+0x1b0): undefined reference to `X509_STORE_CTX_init'
opensslhello.c:(.text+0x1bf): undefined reference to `X509_verify_cert'
opensslhello.c:(.text+0x1d3): undefined reference to `X509_STORE_CTX_get_error'
opensslhello.c:(.text+0x1e3): undefined reference to `X509_STORE_CTX_get_error'
opensslhello.c:(.text+0x215): undefined reference to `X509_STORE_CTX_free'
opensslhello.c:(.text+0x220): undefined reference to `X509_free'
opensslhello.c:(.text+0x22b): undefined reference to `BIO_free'
opensslhello.c:(.text+0x233): undefined reference to `X509_free'
opensslhello.c:(.text+0x23e): undefined reference to `sk_pop_free'
opensslhello.c:(.text+0x249): undefined reference to `X509_STORE_free'
/tmp/ccTahV7g.o: In function `main':
opensslhello.c:(.text+0x291): undefined reference to `EVP_cleanup'
opensslhello.c:(.text+0x29d): undefined reference to `ERR_remove_state'
opensslhello.c:(.text+0x2a2): undefined reference to `ERR_free_strings'
collect2: error: ld returned 1 exit status
root@kali:~/openssl# 

Can anyone please tell me what I should do to, get rid of this error.?

Thanks,

like image 360
Dev.K. Avatar asked Jul 15 '15 07:07

Dev.K.


1 Answers

You haven't linked the crypto and openssl libraries:

gcc opensslhello.c -lssl -lcrypto
like image 82
P.P Avatar answered Sep 20 '22 22:09

P.P