How to compile .c file with OpenSSL includes?

jahmax picture jahmax · Jul 30, 2010 · Viewed 178.5k times · Source

I am trying to compile a small .c file that has the following includes:

#include <openssl/ssl.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <openssl/evp.h>

In the same folder where i have the .c file I have a /openssl with all those files (and more), also in synaptic package manager I see OpenSSL installed, I am trying to compile with this:

gcc -o Opentest Opentest.c -lcrypto

but I always get the errors:

error: openssl/ssl.h: No such file or directory
error: openssl/rsa.h: No such file or directory
error: openssl/x509.h: No such file or directory
error: openssl/evp.h: No such file or directory

The file I want to compile is only a .c file, doesnt have Makefile or ./configure.

I already tried:

env CFLAGS=-I/path/to/openssl/

and tried to compile again but i get the same errors.

What should I do in order to compile with openssl includes?

Answer

caf picture caf · Jul 30, 2010

Your include paths indicate that you should be compiling against the system's OpenSSL installation. You shouldn't have the .h files in your package directory - it should be picking them up from /usr/include/openssl.

The plain OpenSSL package (libssl) doesn't include the .h files - you need to install the development package as well. This is named libssl-dev on Debian, Ubuntu and similar distributions, and libssl-devel on CentOS, Fedora, Red Hat and similar.