本文介绍了如何使用 OpenSSL 编译 .c 文件包括?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个包含以下内容的小型 .c 文件:

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>

在我拥有 .c 文件的同一个文件夹中,我有一个包含所有这些文件(以及更多)的/openssl,也在突触包管理器中我看到安装了 OpenSSL,我正在尝试用这个进行编译:

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

但我总是得到错误:

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

我要编译的文件只是一个.c文件,没有Makefile或./configure.

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

我已经试过了:

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

并试图再次编译,但我得到了同样的错误.

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

我应该怎么做才能使用 OpenSSL 进行编译?

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

推荐答案

您的包含路径表明您应该针对系统的 OpenSSL 安装进行编译.你的包目录中不应该有 .h 文件 - 它应该从 /usr/include/openssl 中获取它们.

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.

普通的 OpenSSL 包 (libssl) 不包含 .h 文件 - 您还需要安装开发包.这在 Debian、Ubuntu 和类似发行版上被命名为 libssl-dev,在 CentOS、Fedora、Red Hat 和类似发行版上被命名为 libssl-devel.

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.

这篇关于如何使用 OpenSSL 编译 .c 文件包括?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:05
查看更多