12

I downloaded OpenSSL sources, and did the config, make, sudo make install trilogy.

I then built my project, linking in libcrypto.a and libssl.a, but got:

ld: warning: in /usr/local/ssl/lib/libcrypto.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in /usr/local/ssl/lib/libssl.a, file was built for unsupported file format which is not the architecture being linked (x86_64)

I'm pretty sure I want to re-build OpenSSL as 32-bit (i386), because (for reasons not pertinent to this question) my project needs to be 32-bit.

How do I build OpenSSL as 32-bit on Mac OS X? (I didn't see anything about this in the "INSTALL" file.)

Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
  • 1
    In general on OS X, 64-bit Intel is called `x86_64`, 32-bit Intel `i386` (see `man arch`). – Ned Deily Nov 03 '10 at 17:06
  • Note, it turns out I didn't need to download and build OpenSSL on Mac OS X (10.6.4). My project built fine once I got the linker (-l) arguments correct. (I'm told the OpenSSL libs "bundled" with Mac OS X are a fat binary that includes all of x86_64, i386 and PPC builds. – Daryl Spitzer Nov 04 '10 at 19:44
  • 1
    That's correct, pretty much everything included with OS X is multi-arch universal. About the only reason to build your own OpenSSL is if you need a newer version. – Ned Deily Nov 04 '10 at 20:40
  • @NedDeily That being the case, would you suggest solving this issue by removing my 64-bit brew install of openssl, so that the build can access OS X's universal?: http://stackoverflow.com/questions/34832512/unable-to-install-32-bit-python-with-pyenv-despite-appropriate-flags-set – Pyderman Jan 16 '16 at 22:03
  • @Pyderman, if you need 32-bit/64-bit up-to-date versions of the OpenSSL libraries, it looks like Homebrew now supports building a universal version; see https://github.com/Homebrew/homebrew/issues/28448. – Ned Deily Jan 17 '16 at 17:52
  • @NedDeily Thanks Ned. Off-topic, and excuse my ignorance, but how do I get a brew install to build a universal version? I understand the `make` process for manually downloaded source, but my understanding is that a `brew install` downloads and the `makes` automatically. Do I need to intercept this process somehow, and if so, how do I make sure the resultant 32-bit build gets installed in `/usr/local/Cellar `or `/usr/local/opt/openssl`? – Pyderman Jan 17 '16 at 22:51
  • @Pyderman, I believe you just need to use the `--universal` option with `brew` but you should ask elsewhere as I don't use Homebrew myself. – Ned Deily Jan 18 '16 at 00:15

2 Answers2

21
$ curl https://www.openssl.org/source/openssl-1.0.0a.tar.gz | tar xz
$ cd openssl-1.0.0a
$ export CFLAGS="-arch i386"
$ export LDFLAGS="-arch i386"
$ ./config
$ make
$ lipo -info libssl.a
input file libssl.a is not a fat file
Non-fat file: libssl.a is architecture: i386
$ lipo -info libcrypto.a
input file libcrypto.a is not a fat file
Non-fat file: libcrypto.a is architecture: i386
Elist
  • 5,313
  • 3
  • 35
  • 73
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • 1
    That's one helluva answer! Neat! – SexyBeast Dec 10 '15 at 19:46
  • I have downloaded openssl-1.0.2g. It seems that config defaults to i686 build, the CFLAGS & LDFLAGS is not necessary. – youfu Mar 02 '16 at 08:21
  • The current stable build as of this date is `openssl-1.1.0i.tar.gz`. Also, for me, the correct way to configure a 32 bit build was: `./Configure darwin-i386-cc` (instead of using the `export` commands and `./configure` command shown above) – M Katz Aug 20 '18 at 08:40
1

If anybody is looking for a solution to build dynamic libraries, this is how to do it:

tar -xvzf <openssl gz file>
./Configure darwin-i386-cc -shared 
make

For 64 bit, run

./Configure darwin64-x86_64-cc -shared
make
SexyBeast
  • 7,913
  • 28
  • 108
  • 196