openssl是加解密经常用到的的一个开源库,很多项目中有用到,比如账号登录,数据库加密,libcurl访问https等,一般我们用到的是在window平台,而且很多都可以在网上找到现成的库,在macos系统用到的比较少,可能是开发少的原因。本篇介绍在macos中编译openssl.
macos系统版本10.15.6
1.到官网下载openssl源码
这里下载的是openssl-1.1.1d 的版本
解压
chenyj-imac:openssl-1.1.1d chenyj$ tar -zxf openssl-1.1.1d.tar.gz
切换到openssl-1.1.1d目录
编译配置
chenyj-imac:openssl-1.1.1d chenyj$ ./config -fPIC no-shared --prefix=/usr/local
Operating system: x86_64-apple-darwinDarwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
Configuring OpenSSL version 1.1.1d (0x1010104fL) for darwin64-x86_64-cc
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub
*** and include the output from the following command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
*** (If you are new to OpenSSL, you might want to consult the ***
*** 'Troubleshooting' section in the INSTALL file first) ***
*** ***
**********************************************************************
WARNING! If you wish to build 32-bit libraries, then you have to
invoke 'KERNEL_BITS=32 ./config '-fPIC' 'no-shared' '--prefix=/usr/local''.
chenyj-imac:openssl-1.1.1d chenyj$
编译
- chenyj-imac:openssl-1.1.1d chenyj$ make
- /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
- "-oMakefile" crypto/include/internal/bn_conf.h.in > crypto/include/internal/bn_conf.h
- /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
- "-oMakefile" crypto/include/internal/dso_conf.h.in > crypto/include/internal/dso_conf.h
- /usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
- "-oMakefile" include/openssl/opensslconf.h.in > include/openssl/opensslconf.h
- /Applications/Xcode.app/Contents/Developer/usr/bin/make depend && /Applications/Xcode.app/Contents/Developer/usr/bin/make _all
- cc -I. -Iinclude -fPIC -arch x86_64 -O3 -Wall -fPIC -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -D_REENTRANT -DNDEBUG -MMD -MF apps/app_rand.d.tmp -MT apps/app_rand.o -c -o apps/app_rand.o apps/app_rand.c
- cc -I. -Iinclude -fPIC -arch x86_64 -O3 -Wall -fPIC -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -D_REENTRANT -DNDEBUG -MMD -MF apps/apps.d.tmp -MT apps/apps.o -c -o apps/apps.o apps/apps.c
- …….
- 编译文件过程........
安装
- chenyj-imac:openssl-1.1.1d chenyj$ sudo make install
- _build_libs
- make[1]: Nothing to be done for `_build_libs'.
- *** Installing runtime libraries
- *** Installing development files
- install ./include/openssl/aes.h -> /usr/local/include/openssl/aes.h
- install ./include/openssl/asn1.h -> /usr/local/include/openssl/asn1.h
- install ./include/openssl/asn1_mac.h -> /usr/local/include/openssl/asn1_mac.h
- install ./include/openssl/asn1err.h -> /usr/local/include/openssl/asn1err.h
- install ./include/openssl/asn1t.h -> /usr/local/include/openssl/asn1t.h
- install ./include/openssl/async.h -> /usr/local/include/openssl/async.h
- install ./include/openssl/asyncerr.h -> /usr/local/include/openssl/asyncerr.h
- install ./include/openssl/bio.h -> /usr/local/include/openssl/bio.h
- …………
- 安装过程........
- /usr/local/share/doc/openssl/html/man3/X509_REVOKED_get_ext_by_critical.html -> /usr/local/share/doc/openssl/html/man3/X509v3_get_ext_by_NID.html
- /usr/local/share/doc/openssl/html/man3/X509_REVOKED_delete_ext.html -> /usr/local/share/doc/openssl/html/man3/X509v3_get_ext_by_NID.html
- /usr/local/share/doc/openssl/html/man3/X509_REVOKED_add_ext.html -> /usr/local/share/doc/openssl/html/man3/X509v3_get_ext_by_NID.html
- /usr/local/share/doc/openssl/html/man5/config.html
- /usr/local/share/doc/openssl/html/man5/x509v3_config.html
- /usr/local/share/doc/openssl/html/man7/bio.html
- /usr/local/share/doc/openssl/html/man7/crypto.html
- /usr/local/share/doc/openssl/html/man7/ct.html
- /usr/local/share/doc/openssl/html/man7/des_modes.html
- /usr/local/share/doc/openssl/html/man7/Ed25519.html
- /usr/local/share/doc/openssl/html/man7/Ed448.html -> /usr/local/share/doc/openssl/html/man7/Ed25519.html
- /usr/local/share/doc/openssl/html/man7/evp.html
- /usr/local/share/doc/openssl/html/man7/ossl_store-file.html
- /usr/local/share/doc/openssl/html/man7/ossl_store.html
- /usr/local/share/doc/openssl/html/man7/passphrase-encoding.html
- /usr/local/share/doc/openssl/html/man7/RAND.html
- /usr/local/share/doc/openssl/html/man7/RAND_DRBG.html
- /usr/local/share/doc/openssl/html/man7/RSA-PSS.html
- /usr/local/share/doc/openssl/html/man7/scrypt.html
- /usr/local/share/doc/openssl/html/man7/SM2.html
- /usr/local/share/doc/openssl/html/man7/ssl.html
- /usr/local/share/doc/openssl/html/man7/X25519.html
- /usr/local/share/doc/openssl/html/man7/X448.html -> /usr/local/share/doc/openssl/html/man7/X25519.html
- /usr/local/share/doc/openssl/html/man7/x509.html
- chenyj-imac:openssl-1.1.1d chenyj$
编译安装完成后,
静态库安装在/usr/local/lib目录下
libssl.a libcrypto.a
头文件安装在/usr/local/include目录下
/usr/local/include/openssl
可执行文件安装在/usr/local/bin目录下
openssl c_rehash
文档安装在/usr/local/share/doc目录下
openssl/html /usr/local/share/man
配置文件安装在/usr/local/share/pkgconfig目录下
libcrypto.pc openssl.pc libssl.pc
参考: