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

主要是看着他的输出目录就没敢用 (不然用个粑粑,最后还是用的上卖弄这4 5步)


----------------------------------下面的就当表演卖萌了----------------------------------------

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

posted @ 2021-12-16 11:13  荧惑微光  阅读(2101)  评论(0编辑  收藏  举报