Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile .c file with OpenSSL includes?

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, doesn't 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?

like image 452
jahmax Avatar asked Jul 30 '10 04:07

jahmax


People also ask

How do I compile OpenSSL source code?

Compiling OpenSSL for Linux on Ubuntu 20.04 In addition to the more advanced . configure script provided with the source, OpenSSL's source directory includes a friendlier . config script with common defaults. Make this script executable and run it.

Where is OpenSSL include Linux?

The standard location of the development libs is /usr/include/openssl . The only shared objects for openssl are in /usr/lib/i386-linux-gnu/openssl-1.0. 0/engines/ .

Where are OpenSSL header files?

Configuration files used by OpenSSL will be in DIR/ssl or the directory specified by --openssldir. --openssldir=DIR Directory for OpenSSL files. If no prefix is specified, the library files and binaries are also installed there.


1 Answers

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.

like image 180
caf Avatar answered Oct 27 '22 19:10

caf