C++ 如何在 Ubuntu 上安装 OpenSSL 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3016956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:47:39  来源:igfitidea点击:

How do I install the OpenSSL libraries on Ubuntu?

c++ubuntuinstallationopenssl

提问by Daryl Spitzer

I'm trying to build some code on Ubuntu 10.04 LTS that uses OpenSSL 1.0.0. When I run make, it invokes g++ with the "-lssl" option. The source includes:

我正在尝试在使用 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>

I ran:

我跑了:

$ 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.

But I guess the openssl package doesn't include the library. I get these errors on make:

但我猜 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?

如何在 Ubuntu 10.04 LTS 上安装 OpenSSL C++ 库?

I did a man g++and (under "Options for Linking") for the -l option it states: " The linker searches a standard list of directories for the library..." and "The directories searched include several standard system directories..." What are those standard system directories?

man g++为 -l 选项做了一个和(在“链接选项”下)它指出:“链接器搜索库的标准目录列表......”和“搜索的目录包括几个标准系统目录......”那些标准的系统目录是什么?

回答by Niki Yoshiuchi

You want to install the development package, which is libssl-dev:

你要安装开发包,也就是libssl-dev:

sudo apt-get install libssl-dev

回答by Yann Ramin

apt-get install libssl-dev

apt-get install libssl-dev

回答by Steve Lemke

How could I have figured that out for myself (other than asking this question here)? Can I somehow tell apt-get to list all packages, and grep for ssl? Or do I need to know the "lib*-dev" naming convention?

我怎么能自己弄清楚(除了在这里问这个问题)?我可以以某种方式告诉 apt-get 列出所有包,并告诉 ssl 的 grep 吗?还是我需要知道“lib*-dev”命名约定?

If you're linking with -lfoothen the library is likely libfoo.so. The library itself is probably part of the libfoopackage, and the headers are in the libfoo-devpackage as you've discovered.

如果您正在链接,-lfoo那么该库很可能是libfoo.so。库本身可能是libfoo包的一部分,而标头就在libfoo-dev您发现的包中。

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 that apt-getsupports bash completion.

有些人使用 GUI“突触”应用程序 ( sudo synaptic) 来(定位和)安装软件包,但我更喜欢使用命令行。更容易从命令行找到正确包的一件事是apt-get支持 bash 补全。

Try typing sudo apt-get install libssland then hit tabto 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).

尝试键入sudo apt-get install libssl然后点击tab查看匹配包名称的列表(当您需要选择具有多个版本或其他可用变体的包的正确版本时,这会有所帮助)。

Bash completion is actually very useful... for example, you can also get a list of commands that apt-getsupports by typing sudo apt-getand then hitting tab.

Bash 补全实际上非常有用……例如,您还可以apt-get通过键入sudo apt-get然后点击来获取支持的命令列表tab

回答by Mann

I found a detailed solution here: Install OpenSSL Manually On Linux

我在这里找到了一个详细的解决方案:在 Linux 上手动安装 OpenSSL

From the blog post...:

从博客文章...:

Steps to download, compile, and install are as follows (I'm installing version 1.0.1g below; please replace "1.0.1g" with your version number):

Step – 1 : Downloading OpenSSL:

Run the command as below :

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz

Also, download the MD5 hash to verify the integrity of the downloaded file for just varifacation purpose. In the same folder where you have downloaded the OpenSSL file from the website :

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz.md5
$ md5sum openssl-1.0.1g.tar.gz
$ cat openssl-1.0.1g.tar.gz.md5

Step – 2 : Extract files from the downloaded package:

$ tar -xvzf openssl-1.0.1g.tar.gz

Now, enter the directory where the package is extracted like here is openssl-1.0.1g

$ cd openssl-1.0.1g

Step – 3 : Configuration OpenSSL

Run below command with optional condition to set prefix and directory where you want to copy files and folder.

$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl

You can replace “/usr/local/openssl” with the directory path where you want to copy the files and folders. But make sure while doing this steps check for any error message on terminal.

Step – 4 : Compiling OpenSSL

To compile openssl you will need to run 2 command : make, make install as below :

$ make

Note: check for any error message for verification purpose.

Step -5 : Installing OpenSSL:

$ sudo make install

Or without sudo,

$ make install

That's it. OpenSSL has been successfully installed. You can run the version command to see if it worked or not as below :

$ /usr/local/openssl/bin/openssl version

OpenSSL 1.0.1g 7 Apr 2014

下载、编译、安装步骤如下(以下我安装的是1.0.1g版本,请将“1.0.1g”替换为你的版本号):

步骤 – 1:下载 OpenSSL:

运行命令如下:

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz

此外,下载 MD5 哈希以验证下载文件的完整性,仅用于变异目的。在您从网站下载 OpenSSL 文件的同一文件夹中:

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz.md5
$ md5sum openssl-1.0.1g.tar.gz
$ cat openssl-1.0.1g.tar.gz.md5

步骤 – 2:从下载的包中提取文件:

$ tar -xvzf openssl-1.0.1g.tar.gz

现在,进入解压包的目录,比如openssl-1.0.1g

$ cd openssl-1.0.1g

第 3 步:配置 OpenSSL

使用可选条件运行以下命令以设置要复制文件和文件夹的前缀和目录。

$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl

您可以将“/usr/local/openssl”替换为要复制文件和文件夹的目录路径。但请确保在执行此步骤时检查终端上是否有任何错误消息。

第 4 步:编译 OpenSSL

要编译 openssl,您需要运行 2 个命令:make, make install 如下:

$ make

注意:检查任何错误消息以进行验证。

步骤-5:安装OpenSSL:

$ sudo make install

或者没有 sudo,

$ make install

就是这样。OpenSSL 已成功安装。您可以运行 version 命令来查看它是否有效,如下所示:

$ /usr/local/openssl/bin/openssl version

OpenSSL 1.0.1g 7 Apr 2014

回答by B.H Xie

Another way to install openssl library from source code on Ubuntu, follows steps below, here WORKDIRis your working directory:

另一种在 Ubuntu 上从源代码安装 openssl 库的方法,请按照以下步骤操作,这WORKDIR是您的工作目录:

sudo apt-get install pkg-config
cd WORKDIR
git clone https://github.com/openssl/openssl.git
cd openssl
./config
make
sudo make install
# Open file /etc/ld.so.conf, add a new line: "/usr/local/lib" at EOF
sudo ldconfig

回答by jonescb

You want the openssl-develpackage. At least I think it's -develon Ubuntu. Might be -dev. It's one of the two.

你想要这个openssl-devel包裹。至少我认为它-devel在 Ubuntu 上。可能是-dev。这是两者之一。

回答by Vincent Fourmond

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-fileto figure out which package provides that file:

作为一般规则,当在 Debian 或 Ubuntu 上并且您缺少开发文件(或任何其他与此相关的文件)时,请使用apt-file确定哪个软件包提供该文件:

~ apt-file search openssl/bio.h
android-libboringssl-dev: /usr/include/android/openssl/bio.h
libssl-dev: /usr/include/openssl/bio.h
libwolfssl-dev: /usr/include/cyassl/openssl/bio.h
libwolfssl-dev: /usr/include/wolfssl/openssl/bio.h

A quick glance at each of the packages that are returned by the command, using apt showwill tell you which among the packages is the one you're looking for:

快速浏览一下命令返回的每个包, usingapt show将告诉您哪些包是您要查找的包:

~ apt show libssl-dev
Package: libssl-dev
Version: 1.1.1d-2
Priority: optional
Section: libdevel
Source: openssl
Maintainer: Debian OpenSSL Team <[email protected]>
Installed-Size: 8,095 kB
Depends: libssl1.1 (= 1.1.1d-2)
Suggests: libssl-doc
Conflicts: libssl1.0-dev
Homepage: https://www.openssl.org/
Tag: devel::lang:c, devel::library, implemented-in::TODO, implemented-in::c,
 protocol::ssl, role::devel-lib, security::cryptography
Download-Size: 1,797 kB
APT-Sources: http://ftp.fr.debian.org/debian unstable/main amd64 Packages
Description: Secure Sockets Layer toolkit - development files
 This package is part of the OpenSSL project's implementation of the SSL
 and TLS cryptographic protocols for secure communication over the
 Internet.
 .
 It contains development libraries, header files, and manpages for libssl
 and libcrypto.

N: There is 1 additional record. Please use the '-a' switch to see it

回答by Nursnaaz

sudo apt-get install libcurl4-openssl-dev

sudo apt-get install libcurl4-openssl-dev