如何在 Ubuntu 上安装 OpenSSL 库?
我正在尝试在使用 OpenSSL 1.0.0 的 Ubuntu 10.04 LTS 上构建一些代码。当我运行 make 时,它会使用“-lssl”选项调用 g++。来源包括:
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/des.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
我跑了:
$ sudo apt-get install openssl
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
但我猜 openssl 包不包含该库。我在 make 时收到以下错误:
foo.cpp:21:25: error: openssl/bio.h: No such file or directory
foo.cpp:22:28: error: openssl/buffer.h: No such file or directory
foo.cpp:23:25: error: openssl/des.h: No such file or directory
foo.cpp:24:25: error: openssl/evp.h: No such file or directory
foo.cpp:25:25: error: openssl/pem.h: No such file or directory
foo.cpp:26:25: error: openssl/rsa.h: No such file or directory
How do I install the OpenSSL C++ library on Ubuntu 10.04 LTS?
我做了一个 man g++
和(在“链接选项”下)它的 -l 选项指出:“链接器搜索库的标准目录列表...”和“搜索的目录包括几个标准系统目录...”那些标准系统目录是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您要安装开发包,即 libssl-dev:
You want to install the development package, which is libssl-dev:
跑步:
Run:
所有这些答案都非常过时,并且从包仍在开发的时候开始。您现在可以使用下面列出的“正常”命令:
编辑:OP 的问题措辞很差...毕竟,OpenSSL 本身就是一个库,所以我在回答之前太快地阅读了他的问题。上面的命令安装“普通”OpenSSL。
在问题的底部,他提到
make
失败,这表明他正在手动编译该包。是的,即使您下载 TAR 球,它也会包含所有openssl
和libssl
文件,然后您可以使用它们来make
。OP真正需要的是OpenSSL开发库,在这种情况下,您可以首先使用上述命令安装OpenSSL,然后运行此命令:
更多信息:https://linuxtect.com/how-to-install-openssl-libraries-on-ubuntu -debian-mint/
All of these answers are very outdated and from when the package was still being developed. You can now just use the "normal" command listed below:
Edit: OP's question is poorly worded... after all, OpenSSL is a library itself, so I read his question too quickly before answering. The command above installs "normal" OpenSSL.
Toward the bottom of his question he mentions that
make
fails, suggesting he is compiling the package manually. And yes, even if you download the TAR ball, it will include all of theopenssl
andlibssl
files, which you can thenmake
from.What OP is really asking for is the OpenSSL Development Library, in which case you can first install OpenSSL using the above command, and then run this afterwards:
More info: https://linuxtect.com/how-to-install-openssl-libraries-on-ubuntu-debian-mint/
我在这里找到了详细的解决方案:Install OpenSSL Manually On Linux
摘自博客文章...:
I found a detailed solution here: Install OpenSSL Manually On Linux
From the blog post...:
如果您使用
-lfoo
链接,则该库可能是libfoo.so
。正如您所发现的,该库本身可能是libfoo
包的一部分,并且标头位于libfoo-dev
包中。有些人使用 GUI“synaptic”应用程序 (
sudo synaptic
) 来(查找和)安装软件包,但我更喜欢使用命令行。 apt-get 支持 bash 补全,这使得从命令行更容易找到正确的包的一件事是。尝试输入
sudo apt-get install libssl
然后点击 tab 查看匹配的包名称列表(当您需要选择正确版本的包时,这会有所帮助)有多个版本或其他可用变体)。Bash 补全实际上非常有用...例如,您还可以通过输入
sudo apt-get
然后点击 支持的命令列表>选项卡。If you're linking with
-lfoo
then the library is likelylibfoo.so
. The library itself is probably part of thelibfoo
package, and the headers are in thelibfoo-dev
package as you've discovered.Some people use the GUI "synaptic" app (
sudo synaptic
) to (locate and) install packages, but I prefer to use the command line. One thing that makes it easier to find the right package from the command line is the fact thatapt-get
supports bash completion.Try typing
sudo apt-get install libssl
and then hit tab to see a list of matching package names (which can help when you need to select the correct version of a package that has multiple versions or other variations available).Bash completion is actually very useful... for example, you can also get a list of commands that
apt-get
supports by typingsudo apt-get
and then hitting tab.在 Ubuntu 上从源代码安装 openssl 库的另一种方法,请按照以下步骤操作,这里
WORKDIR
是您的工作目录:Another way to install openssl library from source code on Ubuntu, follows steps below, here
WORKDIR
is your working directory:作为一般规则,当在 Debian 或 Ubuntu 上并且您缺少开发文件(或任何其他与此相关的文件)时,请使用 apt-file 来找出哪个软件包提供了该文件
:浏览一下命令返回的每个包,使用 apt show 会告诉您哪个包是您要查找的包:
As a general rule, when on Debian or Ubuntu and you're missing a development file (or any other file for that matter), use
apt-file
to figure out which package provides that file:A quick glance at each of the packages that are returned by the command, using
apt show
will tell you which among the packages is the one you're looking for:您需要
openssl-devel
包。至少我认为它是 Ubuntu 上的
-devel
。可能是-dev
。这是两者之一。You want the
openssl-devel
package.At least I think it's
-devel
on Ubuntu. Might be-dev
. It's one of the two.前往官网下载您需要的版本源码
然后解压更新包并执行以下命令
因为默认只生成静态库,所以如果想要动态库,就添加"shared"选项
make &&进行安装
Go to the official website and download the source code for the version you need
Then unzip the update package and execute the following command
Because the default is to generate only static libraries, if you want dynamic libraries, add the "shared" option
make && make install
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libcurl4-openssl-dev