如何使用 OpenSSL 包含编译 .c 文件?

编程入门 行业动态 更新时间:2024-10-28 12:29:02
本文介绍了如何使用 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 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-28 12:34:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/728134.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文件   OpenSSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!