Cross Compile openssl for ARM

Everything is MindGame
2 min readMay 19, 2024

In this short article we will

  • checkout code of openssl
  • compile for x86
  • compile for arm (MAC machine)

What is cross compile?

Cross-compiling means the process of compiling source code on one architecture (the host=x86) to generate binaries that can run on a different architecture (the target=ARM)

Cross-compilation involves using a cross-compiler toolchain. Toolchain contains(compilers, linkers, and other build tools) for target architecture.

Checkout openssl

git clone https://github.com/openssl/openssl.git

Build for x86

gcc, g++ installed in /usr/local/ are meant for x86, so no external toolchain needed

$ cd openssl
$ ./Configure no-shared //If you want static libraries
$ make
$ make install

Build for ARM compiler

Step-1

Download the arm toolchain

Step-2

Select appropriate toolchain for your architecture

Step-3

Extract tool chain at your location.

I extracted at /opt/arm

$ tar -xvf arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
$ mv arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-linux-gnu arm
$ cd /opt/arm
$ ls
aarch64-none-linux-gnu bin include lib lib64 libexec license.txt share
$ cd bin
$ ls
// This contains ARM gcc, g++

Step-4

Build openssl using arm binaries

export CROSS_COMPILE = /opt/arm/bin
export CC = aarch64-none-linux-gnu-gcc
export CXX = aarch64-none-linux-gnu-g++
export AR = aarch64-none-linux-gnu-gcc-ar

$ cd /opt/openssl
$ ./Configure linux-aarch64 --cross-compile-prefix=/opt/arm/bin --prefix=/opt/openssl
$ make -j4
$ make install

Conclusion

We have to provide ARM gcc, g++, ar paths so that openssl generates Makefile using ARM paths, else it openssl will keep pointing to /usr/local

Hope it Helps!

--

--

Everything is MindGame

Comparing New Age programming Languages, Distributed Systems, Blockchain