How to compile .c file with OpenSSL?

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

#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 / openssl with all these files (and more), also in the synaptic package manager I see that OpenSSL is installed, I'm trying to compile with this:

 gcc -o Opentest Opentest.c -lcrypto 

but I always get 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 just a .c file, does not have a Makefile or. / configure.

I have already tried:

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

and tried to compile again, but I get the same errors.

What should I do to compile using openssl?

+66
c compiler-construction linux compiler-errors openssl
Jul 30 '10 at 4:21
source share
7 answers

Your inclusion paths indicate that you should compile according to the OpenSSL system installation. You should not have files .h directory with your packages - you need to collect them from /usr/include/openssl .

libssl OpenSSL package ( libssl ) does not include .h files - you also need to install the development package. This is called libssl-dev on Debian, Ubuntu, and similar distributions, and libssl-devel on CentOS, Fedora, Red Hat, and the like.

+99
Jul 30 '10 at 7:21
source share

Use the -I flag for gcc correctly.

gcc -I/path/to/openssl/ -o Opentest -lcrypto Opentest.c

-I should point to the directory containing the openssl folder.

+9
Jul 30 '10 at 4:23
source share

Use the snippet below as a solution for the cited call;

 yum install openssl yum install openssl-devel 

It has been tested and proven to work on CentOS version 5.4 with version 1.2.7 saved.

+6
Apr 24 '13 at 19:01
source share

If the OpenSSL headers are in the openssl subdirectory of the current directory, use:

 gcc -I. -o Opentest Opentest.c -lcrypto 

The preprocessor attempts to create a name such as " ./openssl/ssl.h " from " . " In the -I option and the name specified in angle brackets. If you #include "openssl/ssl.h" double quotation marks ( #include "openssl/ssl.h" ), you might never need to ask a question; the Unix compiler usually looks for headers enclosed in double quotes in the current directory automatically, but this does not do for headers enclosed in angle brackets ( #include <openssl/ssl.h> ). This is a specific implementation behavior.

You do not say where the OpenSSL libraries are located - you may need to add a suitable option and argument to indicate, for example, " -L /opt/openssl/lib ".

+4
Jul 30 '10 at 5:09
source share

From openssl.pc file

 prefix=/usr exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include Name: OpenSSL Description: Secure Sockets Layer and cryptography libraries and tools Version: 0.9.8g Requires: Libs: -L${libdir} -lssl -lcrypto Libs.private: -ldl -Wl,-Bsymbolic-functions -lz Cflags: -I${includedir} 

You can specify the path to the Include directory and the Libs path. Now your prefix for include /home/username/Programming files. Therefore, your include file should be -I//home/username/Programming .

(Yes, I got this from the comments above)

It is easy to delete logs regarding headers. You can also provide the -L<Lib path> option to link to the -lcrypto library.

+4
Jul 30 '10 at 6:06
source share

You need to specify the path to the library (-L / usr / local / lib /)

gcc -o Opentest Opentest.c -L/usr/local/lib / -Lssl -Lcrypto

It works for me.

+3
Feb 01 '18 at 19:40
source share

For this gcc error, you should refer to the gcc document on the search path .

In short:

1) If you use angle brackets (<>) with # include, gcc will first look for the header file from the system path, for example / usr / local / include and / usr / include, etc.

2) The path specified by the -Ldir command-line option will run in front of the default directories.

3) If you use a quote (") C # include as #include" file ", you will first look for the directory containing the current file.

so the answer to your question is as follows:

1) If you want to use the header files in the source folder, replace <> with "" in the #include directive.

2) if you want to use the -I command line option, add it to your compiled command line (if you set CFLAGS in environment variables, it will not be referenced automatically)

3) About the package configuration (openssl.pc), I do not think that it will be referenced without an explicit declaration in the assembly configuration.

+1
Feb 17 '16 at 8:28
source share



All Articles