1. 程式人生 > 其它 >ubuntu安裝指定版本的openssl

ubuntu安裝指定版本的openssl

別人都安新版本,我tm可好,安老的

在編譯bcclient時,make失敗

root@z-E7:*******/bcclient/libbitcoin# make
Making all in include/bitcoin
make[1]: 進入目錄“/root/src/bcclient/libbitcoin/include/bitcoin”
make[1]: 對“all”無需做任何事。
make[1]: 離開目錄“/root/src/bcclient/libbitcoin/include/bitcoin”
Making all in src
make[1]: 進入目錄“/root/src/bcclient/libbitcoin/src”
  CXX      satoshi_serialize.lo
In file included from ./../include/bitcoin/constants.hpp:25:0,
                 from ./../include/bitcoin/satoshi_serialize.hpp:23,
                 from satoshi_serialize.cpp:20:
./../include/bitcoin/utility/big_number.hpp:91:12: error: field ‘bignum_’ has incomplete type ‘BIGNUM {aka bignum_st}’
     BIGNUM bignum_;
            ^~~~~~~
In file included from /usr/include/openssl/bn.h:19:0,
                 from ./../include/bitcoin/utility/big_number.hpp:23,
                 from ./../include/bitcoin/constants.hpp:25,
                 from ./../include/bitcoin/satoshi_serialize.hpp:23,
                 from satoshi_serialize.cpp:20:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM {aka struct bignum_st}’
 typedef struct bignum_st BIGNUM;
                ^~~~~~~~~
Makefile:603: recipe for target 'satoshi_serialize.lo' failed
make[1]: *** [satoshi_serialize.lo] Error 1
make[1]: 離開目錄“/root/src/bcclient/libbitcoin/src”
Makefile:511: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

擁嗚啥呢,我也不知道
在看原始碼big_number.hpp:91行的BIGNUM bignum_;提示這個BIGNUM有問題,而最開頭倒入了#include<openssl/bn.h>
反正就是openssl升級了,API改了

結果呢,還是不好使。。。白忙

最開始找到方法比較簡易

wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz
tar -xvzf openssl-1.0.2a.tar.gz
cd openssl-1.0.2a
./config --prefix=/usr/
make && make install

主要是看著他的輸出目錄就沒敢用

1.下載

這裡我看一般教程都放在了/usr/local/src下面,我嫌麻煩。。。

wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz
tar -xvzf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g

2.配置編譯

./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
make depend
make
make test

make depend是配置後的提示:building前需要,我不懂啥意思就照做了
--prefix和--openssldir =設定OpenSSL的輸出路徑。
shared = force來建立一個共享庫。
zlib =使用zlib庫啟用壓縮。

3.安裝

make install

過程:

點選檢視程式碼
make[2]: 離開目錄“/usr/local/ssl/lib”
make[1]: 離開目錄“/usr/local/ssl/lib”
OpenSSL shared libraries have been installed in:
  /usr/local/ssl

If this directory is not in a standard system path for dynamic/shared
libraries, then you will have problems linking and executing
applications that use OpenSSL libraries UNLESS:

* you link with static (archive) libraries.  If you are truly
  paranoid about security, you should use static libraries.
* you use the GNU libtool code during linking
  (http://www.gnu.org/software/libtool/libtool.html)
* you use pkg-config during linking (this requires that
  PKG_CONFIG_PATH includes the path to the OpenSSL shared
  library directory), and make use of -R or -rpath.
  (http://www.freedesktop.org/software/pkgconfig/)
* you specify the system-wide link path via a command such
  as crle(1) on Solaris systems.
* you add the OpenSSL shared library directory to /etc/ld.so.conf
  and run ldconfig(8) on Linux systems.
* you define the LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH (HP),
  DYLD_LIBRARY_PATH (MacOS X) or PATH (Cygwin and DJGPP)
  environment variable and add the OpenSSL shared library
  directory to it.

One common tool to check the dynamic dependencies of an executable
or dynamic library is ldd(1) on most UNIX systems.

See any operating system documentation and manpages about shared
libraries for your version of UNIX.  The following manpages may be
helpful: ld(1), ld.so(1), ld.so.1(1) [Solaris], dld.sl(1) [HP],
ldd(1), crle(1) [Solaris], pldd(1) [Solaris], ldconfig(8) [Linux],
chatr(1) [HP].
cp libcrypto.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/libcrypto.pc
cp libssl.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/libssl.pc
cp openssl.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/openssl.pc

4 配置連結庫

cd /etc/ld.so.conf.d/
vim openssl-1.0.2g.conf

# 檔案中新增庫路徑
/usr/local/ssl/lib
# 儲存退出

重新載入動態連結

ldconfig -v
結果輸出
/sbin/ldconfig.real: 無法對 /usr/local/lib/x86_64-linux-gnu 進行 stat 操作: 沒有那個檔案或目錄
/sbin/ldconfig.real: 多次給出路徑“/lib/x86_64-linux-gnu”
/sbin/ldconfig.real: 多次給出路徑“/usr/lib/x86_64-linux-gnu”
/usr/lib/x86_64-linux-gnu/libfakeroot:
	libfakeroot-0.so -> libfakeroot-tcp.so
/usr/local/lib:
	libbitcoinconsensus.so.0 -> libbitcoinconsensus.so.0.0.0
/usr/local/ssl/lib:
	libcrypto.so.1.0.0 -> libcrypto.so.1.0.0
	libssl.so.1.0.0 -> libssl.so.1.0.0
/lib/x86_64-linux-gnu:
	libdbus-1.so.3 -> libdbus-1.so.3.19.4
	libgcc_s.so.1 -> libgcc_s.so.1
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.27.so is the dynamic linker, ignoring
	ld-linux-x86-64.so.2 -> ld-2.27.so
	
.......
	
	libshotwell-authenticator.so.0 -> libshotwell-authenticator.so.0.28.4
/lib:
/usr/lib:
	libnetpbm.so.10 -> libnetpbm.so.10.0
	libnatpmp.so.1 -> libnatpmp.so.1
	libgjs.so.0 -> libgjs.so.0.0.0

5 配置二進位制檔案

備份:

mv /usr/bin/c_rehash /usr/bin/c_rehash.BEKUP
mv /usr/bin/openssl /usr/bin/openssl.BEKUP
vim /etc/environment


#看看之前有沒有舊的ssl路徑,刪掉
#新增:
/usr/local/ssl/bin

6 更新環境

source /etc/environment

7 測試

which openssl
# /usr/local/ssl/bin/openssl

openssl version -v
# OpenSSL 1.0.2g  1 Mar 2016

測試程式碼自己寫吧

參考:
https://blog.csdn.net/weixin_44302212/article/details/113488894
https://www.jianshu.com/p/b7e392b1b90c
https://blog.csdn.net/weixin_30299539/article/details/98981318
https://www.cnblogs.com/thechosenone95/p/10603110.html

本文來自部落格園,作者:熒惑微光,轉載請註明原文連結:https://www.cnblogs.com/yinghuoweiguang/p/15697004.html