Compile the GNU MPFR Library for ARM Cortex M7
In a previous post, I described how to compile GMP (GNU MP) for Cortex M4 (eg: stm32f4) target on a Mac. I thought I would follow up and describe the steps required to build MPFR for cortex-m7 target on Mac. These steps should work just as well on Linux also.
MPFR library is a C library for multiple-precision floating-point computations. From their web site, it is described as follows.
The main goal of MPFR is to provide a library for multiple-precision floating-point computation which is both efficient and has a well-defined semantics
It is quite a popular library, cited by many publications and is definitely a worthwhile addition to your toolbox. So, lets see how to cross compile this library on Mac for the cortex m7 target.
One thing to note is that MPFR depends on GMP, so 2 downloads will be required. Also it is assumed I assume you already have GNU ARM Embedded Toolchain installed and working
Create a directory and download GMP and MPFR
mkdir arm_f7_builds cd arm_f7_builds curl -O https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2 curl -O http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.bz2 tar -xf gmp-6.1.2.tar.bz2 tar -xf mpfr-3.1.5.tar.bz2
Build GMP and install.
mkdir tools cd gmp-6.1.2 mkdir build_stm32f7 cd build_stm32f7/ export PATH=/Users/frank/opt/gcc-arm-none-eabi-6-2017-q1-update/bin/:$PATH ../configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m7" --host=arm-none-eabi \ --disable-assembly --prefix=/Users/frank/arm_f7_builds/tools/ make make install cd ../..
Build MPFR and install. Notice how we point to the location where we just installed GMP.
cd mpfr-3.1.5 mkdir build_stm32f7 cd build_stm32f7/ ../configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m7" --host=arm-none-eabi \ --prefix=/Users/frank/arm_f7_builds/tools/ --with-gmp-include=/Users/frank/arm_f7_builds/tools/include/ \ --with-gmp-lib=/Users/frank/arm_f7_builds/tools/lib make make install cd ../..
Lets examine the resulting directory structure.
tree tools/ ✔ ~/arm_f7_builds 16:32 $ tree tools/ tools/ ├── include │ ├── gmp.h │ ├── mpf2mpfr.h │ └── mpfr.h ├── lib │ ├── libgmp.a │ ├── libgmp.la │ ├── libmpfr.a │ └── libmpfr.la └── share ├── doc │ └── mpfr │ ├── AUTHORS │ ├── BUGS │ ├── COPYING │ ├── COPYING.LESSER │ ├── FAQ.html │ ├── NEWS │ ├── TODO │ └── examples │ ├── ReadMe │ ├── divworst.c │ ├── rndo-add.c │ ├── sample.c │ └── version.c └── info ├── dir ├── gmp.info ├── gmp.info-1 ├── gmp.info-2 └── mpfr.info
Great, we can see both the static libraries (libgmp.a and libmpfr.a) and the header files (gmp.h and mpfr.h) are available.
In a follow up article, I will use show how to use the static MPFR library in a demo project for a Cortex M7 board (eg: STM32F7 Discovery Board).