I need to build OpenSSL on OS X for 32 and 64 bit architectures. What are the options I need to give to ./Configure so that I get it built for both architectures into same .a file?
./Configure so that I get it built for both architectures into same .a file?
You have to be careful with OpenSSL and multiarch libraries because the library is not multiarch safe. That's because each configuration has its own <openssl/opensslconf.h> file, and each platform's BIGNUM is different.
The same procedure detailed below applies to iOS, too. The only thing that changes is the -arch. For iOS, you will probably use armv7, armv7s, arm64 and i386 (for 32-bit simulator debug) and x86_64 (for 64-bit simulator debug).
There's another not-so-apparent trick required. OpenSSL hard codes some default paths based on --prefix and --openssldir, so you have to build 32-bit for the installation directory, install, and then move it; then build 64-bit for the installation directory, install, and then move it; and then create the fat library in the install directory. Also see How to determine the default location for openssl.cnf?
Finally, do not replace OS X's supplied OpenSSL. OpenSSL 1.0.x and 1.1.x are not binary compatible with the Apple's 0.9.8 version of OpenSSL. Because of incompatibilities, the procedures below uses $HOME/ssl. You can use /usr/local/ssl or any other location that suits your taste.
Before you begin, OpenSSL wiki has a page on Compilation and Installation. There's lots of options to supply to config. Choose the ones that suit your taste. I always use no-ssl2, and usually use no-ssl3, no-comp. On mobile devices I use no-srp, no-psk, no-hw, no-dso and no-engines.
Here are the instructions for building the library. You will configure, build, install and then move for each architecture you are supporting in your multiarch build.
32-bit
make clean && make dclean
KERNEL_BITS=32 ./config no-ssl2 no-ssl3 --prefix=$HOME/ssl
make depend
make
make install_sw
mv $HOME/ssl/include/openssl/opensslconf.h $HOME/ssl/include/openssl/opensslconf-x86.h
mv $HOME/ssl/include/openssl/bn.h $HOME/ssl/include/openssl/bn-x86.h
mv $HOME/ssl/ $HOME/ssl-x86
64-bit
make clean && make dclean
KERNEL_BITS=64 ./config no-ssl2 no-ssl3 --prefix=$HOME/ssl
make depend
make
make install_sw
mv $HOME/ssl/include/openssl/opensslconf.h $HOME/ssl/include/openssl/opensslconf-x64.h
mv $HOME/ssl/include/openssl/bn.h $HOME/ssl/include/openssl/bn-x64.h
mv $HOME/ssl/ $HOME/ssl-x64
Headers
You need to copy one set of headers (it does not matter which), copy opensslconf-x86.h, opensslconf-x64.hbn-x86.h and bn-x64.h, create a new <openssl/opensslconf.h>, create a new <openssl/bn.h>, and finally create the multiarch libraries.
At this point, you have a x86 build of the library located at $HOME/ssl-x86 and a x64 build of the library located at $HOME/ssl-x64. You combine them with lipo at $HOME/ssl.
OpenSSL build page now links to this answer. For many years i've been wondering why can't they have headers that match for all platforms instead of that nonsense that they have, like opnessl is special from all other projects.
– Pavel PFeb 12 '19 at 19:24
Hi, there are some "minor" issued in your solution. The syntax for creating symlinks is ln -s . I'm sure, this is a typo. The CLANG flags for INCLUDE and Library path must not be space seperated ! So -I -L is the correct syntax.
– Hannes StoolmannMar 11 '23 at 06:53