openssl 编译安装

官方下载地址:https://www.openssl.org/source/

#解压
$ tar -zxvf openssl-1.1.0h.tar.gz
$ cd openssl-1.1.0h

#配置(使用sudo是因为要prefix的访问权限)
$ sudo ./config --prefix=/usr/local/openssl
该步骤出现如下警告
Configured for darwin-i386-cc.
wanzhihuideMacBook-Pro:openssl-1.1.0h wanzhihui$ sudo ./config --prefix=/usr/local/ --openssldir=/usr/local/openssl darwin64-x86_64-cc
Operating system: i686-apple-darwinDarwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64
WARNING! If you wish to build 64-bit library, then you have to
         invoke './Configure darwin64-x86_64-cc' *manually*.
         You have about 5 seconds to press Ctrl-C to abort.

openssl/config脚本会根据$KERNEL_BITS来判断是否开启x86_64编译,默认是不开启的,所以你生成的openssl库文件是32位的,最后静态链接到nginx会出错。
解决方法:
找到makefile将里面的PLATFORM=dist改成
PLATFORM=darwin64-x86_64-cc

#配置、编译和安装
$ export KERNEL_BITS=64
$ sudo ./config darwin64-x86_64-cc  --prefix=/usr/local/openssl
$ sudo make
$ sudo make install

#查看版本
$ openssl version


不编译64位的在安装nginx时会报链接错误:
-L/usr/local/lib -lpcre /usr/local/openssl/lib/libssl.a /usr/local/openssl/lib/libcrypto.a -lz
ld: warning: ignoring file /usr/local/openssl/lib/libssl.a, file was built for archive which is not the architecture being linked (x86_64): /usr/local/openssl/lib/libssl.a
ld: warning: ignoring file /usr/local/openssl/lib/libcrypto.a, file was built for archive which is not the architecture being linked (x86_64): /usr/local/openssl/lib/libcrypto.a
Undefined symbols for architecture x86_64:
  "_ASN1_GENERALIZEDTIME_print", referenced from:
      _ngx_ssl_stapling_ocsp_handler in ngx_event_openssl_stapling.o
  "_ASN1_d2i_bio", referenced from:
      _ngx_ssl_stapling in ngx_event_openssl_stapling.o
  "_BIO_ctrl", referenced from:
      _ngx_ssl_get_raw_certificate in ngx_event_openssl.o
      _ngx_ssl_get_serial_number in ngx_event_openssl.o
      _ngx_ssl_stapling_ocsp_handler in ngx_event_openssl_stapling.o
  "_BIO_free", referenced from:

猜你喜欢

转载自blog.csdn.net/moonpure/article/details/83051462