back to index

libmpdec/libmpdec++ cross compilation

Package information

Linux

The examples here are for Debian. For other distributions it is just a matter of finding the gcc/g++ cross compiler package names.

ARM32 (gcc)


sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

tar xvf mpdecimal-2.5.1.tar.gz
cd mpdecimal-2.5.1

mkdir arm32
./configure --host=arm-linux-gnueabi --prefix=$PWD/arm32
make
make install

# Now copy the relevant files from the ./arm32 directory to the target machine.

ARM64 (gcc)


sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

tar xvf mpdecimal-2.5.1.tar.gz
cd mpdecimal-2.5.1

mkdir arm64
./configure --host=aarch64-linux-gnu --prefix=$PWD/arm64
make
make install

# Now copy the relevant files from the ./arm64 directory to the target machine.

ARM64 (clang)

Cross compiling with clang is more complex since it requires --target, --sysroot, its own linker and some additional include hints.


# clang also uses the tool chain pulled in by these packages.
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

# clang needs its own linker.
sudo apt-get install lld

tar xvf mpdecimal-2.5.1.tar.gz
cd mpdecimal-2.5.1

mkdir arm64
./configure --host=aarch64-linux-gnu --prefix=$PWD/arm64 CC=clang CXX=clang++ \
            CFLAGS="--target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu" \
            CXXFLAGS="--target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu -I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu" \
            LDFLAGS="--target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu -fuse-ld=lld" \
            LDXXFLAGS="--target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu -fuse-ld=lld"
make
make install

# Now copy the relevant files from the ./arm64 directory to the target machine.

Other

For other architectures one has to find the correct GNU triplet to pass to configure (Example: --host=arm-linux-gnueabi) and the corresponding cross compiler packages. See here for more information.

macOS

Compiling for macOS on Linux

See here for more information.

gcc

There are some gcc cross compilers for macOS. Using these, it should be possible to use the same GNU triplet approach as above.

clang

The approach should be the same as in the ARM64 (clang) section above. You need to install the relevant cross tool chain and lld. Then replace --host, --target, --sysroot and the includes with the correct values for macOS.


Contact:

Stefan Krah <website @ bytereef.org>