title: Getting libcrypto ar error while compiling OpenSSL for Mac
body: <p>I have been able to compile a specific version of OpenSSL for iOS devices, and I am now trying to compile for Mac OSX. However, when I run my bash script (provided below) I am getting the following error:</p>
  
  <pre><code>ar  r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
  ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
  ar: ../../libcrypto.a: Inappropriate file type or format
  </code></pre>
  
  <p>When I run <code>lipo -info libcrypto.a</code> I get the following result:</p>
  
  <pre><code>Architectures in the fat file: libcrypto.a are: i386 x86_64 
  </code></pre>
  
  <p>This does not make any sense, as my bash script is only configuring OpenSSL for i386 (I was looping to do both, but removed x86_64 once I started getting these problems).</p>
  
  <p>I have tried following the answers for similar SO questions <a href="https://stackoverflow.com/questions/4084210/how-do-i-build-openssl-as-32-bit-i386-on-mac-os-x">here</a> and <a href="https://stackoverflow.com/questions/25530429/build-multiarch-openssl-on-os-x/25531033#25531033">here</a>. However, those yielded the same results. Additionally, the Mac installation instructions on the <a href="https://wiki.openssl.org/index.php/Compilation_and_Installation#Mac" rel="nofollow noreferrer">OpenSSL Wiki</a> were of no help either.</p>
  
  <hr>
  
  <p>My scripts:</p>
  
  <p><strong>Build.sh</strong></p>
  
  <pre><code>projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd )"
  ARCHS=("i386")
  FIPS_VERSION="2.0.12"
  OPENSSL_VERSION="1.0.2g"
  
  rm -rf openssl* fips*
  if [ -d "out" ]; then
      rm -rf out
  fi
  
  mkdir out
  source ./Build-FIPS.sh
  cd $projectDir
  source ./Build-OpenSSL.sh
  </code></pre>
  
  <p><strong>Build-OpenSSL.sh</strong></p>
  
  <pre><code>set -e
  
  function main() {
      verifyopenssl
      for ((i=0; i &lt; ${#ARCHS[@]}; i++))
      do
          makeopenssl "${ARCHS[i]}"
      done
  }
  
  function verifyopenssl() {
      gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
      tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
      cd openssl-$OPENSSL_VERSION
  }
  
  function makeopenssl() {
      BUILD_ARCH=$1
      SDK_NAME="macosx"
      GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
      SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
      MACHINE="darwin-i386-cc"
  #   BSD_ARCH="BSD-generic32"
  
      CONFIG_ARGS="$MACHINE \
          $BSD_ARCH \
          --openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
          fips \
          --with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
          no-idea \
          no-cast \
          no-seed \
          no-md2 \
          no-sha0 \
          no-whirlpool \
          -DL_ENDIAN"
  
      export CC="${GCC} -arch ${BUILD_ARCH}"
      export CFLAGS="-isysroot ${SDK_PATH} -I ${projectDir}/out/fips_${BUILD_ARCH}/include"
      export LDFLAGS="-arch $BUILD_ARCH"
      ./Configure ${CONFIG_ARGS}
  
      make depend
      make
      # make install
      # make clean &amp;&amp; make dclean
  }
  
  main $@
  </code></pre>