Mac本身已经有OpenSSL可以直接用,提供的相关的依赖库如下:

XCLiMac:openssl-0.9.8zg xcl$ ls -l /usr/lib/libssl.dylib
lrwxr-xr-x 1 root wheel 18 11 13 2014 /usr/lib/libssl.dylib -> libssl.0.9.8.dylib

XCLiMac:openssl-0.9.8zg xcl$ ls -alt /usr/lib/libcrypto.dylib
lrwxr-xr-x 1 root wheel 21 11 13 2014 /usr/lib/libcrypto.dylib -> libcrypto.0.9.8.dylib


去官网https://www.openssl.org/下载源码.


编译OpenSSL:


./Configure darwin64-x86_64-cc --prefix=/Users/xcl/Desktop/openssl/myopenssl --openssldir=/usr/local/ssl
make

会编译出静态库:

-- libssl.a libcrypto.a
XCLiMac:openssl-0.9.8zg xcl$ ls lib*
libcrypto.a libcrypto.pc libssl.a libssl.pc


编译动态库加上shared参数即可


-- 生成 libssl.dylib  libcrypto.dylib
./Configure darwin64-x86_64-cc -shared --prefix=/Users/xcl/Desktop/openssl/myopenssl --openssldir=/usr/local/ssl
XCLiMac:openssl-0.9.8zg xcl$ openssl version -a
OpenSSL 1.0.2a 19 Mar 2015
built on: reproducible build, date unspecified
platform: darwin64-x86_64-cc
options: bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: /usr/bin/clang -I. -I.. -I../include -fPIC -fno-common -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/opt/local/etc/openssl"