introduction
OpenSSL is a fully functional software library, which contains open source implementations of transport layer security (TLS) and secure socket layer (SSL) protocols to protect information transmitted through computer networks. CMake is a cross platform 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, statically compile OpenSSL and use it as a cmake third-party library. If you encounter the following errors:
collect2: error: ld returned 1 exit status ld returned 1 exit status Utilities/cmcurl/CMakeFiles ...
So that's the purpose and summary of my blog post. There is a project that needs high versions of boost and cmake. After going through some pits, open a blog to record it.
openssl upgrade
Generally, openssl is updated because the host version is too old to be compatible with the new version of cmake. Here, the lower version refers to those below 1.1.0. For example, I enter openssl version on a server, and its version number is 1.0.2 in 2016:
# openssl version OpenSSL 1.0.2g 1 Mar 2016
At present, openssl adapted to cmake is updated. According to the online tutorial, it is generally 1.1.1k. Although I seem to see 3 on the official website, too new is not necessarily good, so the following is based on 1.1.1k:
# Download the openssl installation package and unzip it wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz tar -xvf openssl-1.1.0k.tar.gz # Compile and install cd openssl-1.1.1k/ ./config make install
Generally, there is no problem with the above. The main problem is to start or view the version number after compilation. It should be noted here that it is best not to directly remove openssl, because if the above is not configured, the subsequent verification of HTTPS network will fail. You can select 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 errors here are:
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 libc Conf link configuration, just add it. And if the user in the anaconda environment replaces / usr/bin/openssl above, after entering the openssl version, it will report xxxx/anaconda3/bin/openssl: there is no such file or directory. The reason is that when the system looks for the keyword openssl, it first finds anaconda3 in 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 the source of cmake is available in the Ubuntu standard warehouse, the version is too old. At present, if you want a new cmake, it is compiled based on the source code. The process is as follows:
First, like openssl, check the version:
cmake -version # cmake version 2.8.12.2
If openssl is OK, cmake will not have any major problems. The installation steps are as follows:
# Uninstall old version apt remove cmake # Install the new version of this package and unzip it wget http://www.cmake.org/files/v3.16/cmake-3.16.6.tar.gz tar -xvf cmake-3.16.6.tar.gz # compile 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, I had a problem with the compilation. In make, 50% of the time, I was prompted about the error at the beginning of the article. Then I found that the openssl version couldn't keep up, so I updated it. After the update was ok, it's OK to rebuild and compile here. Here, bootstrap does not specify a path, so it will be loaded into the system variable by default. If a path is specified, a soft link needs to be added, because the old version has been deleted with remove.
If there is any problem with bootstrap, you can enter/ bootstrap --help to view relevant parameters.
boost upgrade
Boost library is the general name of some C + + program libraries that provide extensions for C + + language standard library. It is developed and maintained by boost community organizations. The boost library can work perfectly with the C + + standard library and provide extended functions for it.
Here is a basic reference: Compilation and installation of Ubuntu - Boost library
Because I only install the boost library to build a middleware, I finally need to compile lightgbm, and light needs boost, just like openssl and cmake, so I heard a long time ago that the boost library is large and powerful, but I can't use it. Here, take boost 1.68.0 as an example:
# Download and unzip 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/ # Dependency installation sudo apt-get update sudo apt-get install build-essential \ g++ \ autotools-dev \ libicu-dev \ libbz2-dev # #Uninstall old version # 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 #View boost version information cat /usr/local/include/boost/version.hpp | grep "BOOST_LIB_VERSION" #Output such as: # // BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION # define BOOST_LIB_VERSION "1_68"
This completes the installation and loads it into the environment variable:
""" Add environment variable """ sudo vim /etc/profile #Add the following: # CPLUS_INCLUDE_PATH=/usr/local/include # LIBRARY_PATH=/usr/local/lib source /etc/profile """ Establish soft connection """ cd /usr/local/lib sudo ln -s libboost_python-py37.so libboost_python3.so sudo ln -s libboost_python-py37.a libboost_python3.a # Build to / usr / lib / x86_ Soft connection of 64 Linux GNU path 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
This completes the required environment!
The following figure is a screenshot of compilation dependent on the above environment: