Update summary of openssl, cmake and boost under linux

introduction

OpenSSL is a full-featured software library containing open-source implementations of the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols for protecting information transmitted over computer networks. CMake is a cross-platform compilation (Build) tool, which can describe the compilation process of all platforms with simple statements.

If you need to install a new version of cmake above 3.16, you generally need to upgrade openssl, compile OpenSSL statically and use it as a third-party library for CMake, if you encounter the following errors:

collect2: error: ld returned 1 exit status
ld returned 1 exit status Utilities/cmcurl/CMakeFiles ...

Then it is the purpose and summary of my blog post. There is a project that requires high versions of boost and cmake. I have gone through some pits and recorded it in the opening blog.

openssl upgrade

Generally, openssl is updated because the version of the host is too old, and it is difficult to be compatible with the new version of cmake. The low version here refers to those below 1.1.0. For example, when I enter openssl version on a certain server, its version number is 1.0.2 in 2016:

# openssl version
OpenSSL 1.0.2g  1 Mar 2016

At present, the openssl that adapts to cmake is updated. According to the online tutorial, it is generally 1.1.1k. Although I seem to have seen 3 on the official website, it is not necessarily good if it is too new, so the following is still based on 1.1.1k:

# 下载openssl安装包解压
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xvf openssl-1.1.0k.tar.gz

# 编译安装
cd openssl-1.1.1k/
./config
make install

There is generally no problem with the above. The main problem is to start or check the version number after the compilation is completed. It should be noted here that it is best not to remove openssl directly, because if the above is not configured, then the verification of the HTTPS network will be Failed, so you can use the above method to compile, and then directly overwrite:

ln -s /usr/local/bin/openssl /usr/bin/openssl

ln -s /usr/local/include/openssl /usr/include/openssl

echo "/usr/lib" >> /etc/ld.so.conf.d/libc.conf

ldconfig

The error here will be:

bin/openssl: relocation error: bin/openssl: symbol EVP_mdc2 version OPENSSL_1_1_0 not defined in file libcrypto.so.1.1 with link time reference

This is because /usr/lib is not added to the libc.conf link configuration, just add it. And if there is a user in the anaconda environment, the above replaces /usr/bin/openssl. After entering the openssl version, it will report xxxx/anaconda3/bin/openssl: there is no such file or directory , the reason is that the system finds the key of openssl At the time of writing, we first found anaconda3 under the system environment variable, but anaconda still uses the old openssl, so we need to replace it:

ln -s /usr/bin/openssl /home/xxx/anaconda3/bin/openssl

Then enter openssl version to see the version number:

root@xx-PowerEdge-R740:/# openssl version
OpenSSL 1.1.1k  25 Mar 2021

At this point, openssl is compiled successfully.

cmake upgrade

Like openssl, cmake also needs to be upgraded. Although there is a source of cmake in the Ubuntu standard repository, the version is too old. At present, if you want a newer cmake, it is compiled based on the source code. The process is as follows:

First, like openssl, check the version first:

cmake -version
# cmake version 2.8.12.2

If it is determined that there is no problem with openssl, then there will be no major problems with cmake. The installation steps are as follows:

# 卸载旧版本
apt remove cmake

# 安装新版本包并解压
wget http://www.cmake.org/files/v3.16/cmake-3.16.6.tar.gz
tar -xvf cmake-3.16.6.tar.gz

# 编译
sudo chmod -R 777 cmake-3.16.6
cd cmake-3.16.6/
apt-get install build-essential 
./bootstrap
make -j4
make install

At that time, when I was compiling, the problem was in make. When it reached 50%, I was prompted that the error at the beginning of the article was wrong. Then I found that the openssl version could not keep up, so I updated it. After the update is fine, I will do it again here The build compiles fine. Here bootstrap does not specify the path, so it will be loaded into the system variable by default. If the path is specified, a soft link needs to be added, because the old version has been deleted with remove.

If you encounter any problems with bootstrap, you can enter ./bootstrap --help to view the relevant parameters.

boost upgrade

Boost library is a general term for some C++ program libraries that provide extensions to the C++ language standard library, and is developed and maintained by the Boost community organization. The Boost library works perfectly with the C++ standard library and provides extended functionality for it.

Here is a basic reference: Ubuntu - Boost library compilation and installation

Because I installed the boost library just to start a middleware, I finally need to compile lightgbm, and light needs to use boost, just like openssl and cmake, so I heard a long time ago that the boost library is very large and strong, but I use No, here is boost 1.68.0 as an example:

# 下载并解压
wget -O https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
tar xzvf boost_1_68_0.tar.gz
cd boost_1_68_0/

# 依赖项安装
sudo apt-get update  
sudo apt-get install build-essential \
                     g++ \
                     autotools-dev \
                     libicu-dev \
                     libbz2-dev

# #卸载旧版本
# uninstall dpkg
sudo apt --purge remove libboost-dev
sudo apt --purge remove libboost-all-dev
sudo apt --purge autoremove libboost-all-dev
 
# to uninstall the version which we installed from source
sudo rm -rf /usr/lib/libboost_*
sudo rm -rf /usr/include/boost
 
./bootstrap.sh
./b2 --with-python include="/usr/local/include/python3.7m/" 
sudo ./b2 install -j4 
 
# Add the Boost libraries path to the default Ubuntu library search path
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/boost.conf'
 
sudo  ldconfig
 
#查看 boost 版本信息
cat /usr/local/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
#输出如:
#  //  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#  define BOOST_LIB_VERSION "1_68"

At this point, the installation is complete, and then load it into the environment variable:

"""
添加环境变量
"""
sudo vim /etc/profile
#添加如下内容:
#  CPLUS_INCLUDE_PATH=/usr/local/include
#  LIBRARY_PATH=/usr/local/lib
source /etc/profile

"""
建立软连接
"""
cd /usr/local/lib  
sudo ln -s libboost_python-py37.so libboost_python3.so  
sudo ln -s libboost_python-py37.a libboost_python3.a  
 
# 建立到 /usr/lib/x86_64-linux-gnu 路径的软连接
sudo cp /usr/local/lib/libboost_python37.a  /usr/lib/x86_64-linux-gnu/libboost_python-py37.a
sudo cp /usr/local/lib/libboost_python37.so.1.68.0  /usr/lib/x86_64-linux-gnu/libboost-py37.so

At this point, the required environment is complete!

The following figure shows the compilation screenshots that depend on the above environment:

insert image description here

Guess you like

Origin blog.csdn.net/submarineas/article/details/122373989