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-4.0.0.tar.gz
cd mpdecimal-4.0.0

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

# Download the official tests (optional):
cd tests && ./gettests.sh && cd ..

# Build the tests (optional):
cd tests && make && cd ..
cd tests++ && make && cd ..

# Copy the tests (optional):
mkdir arm32/tests
cp tests/runtest arm32/tests
cp -a tests/testdata arm32/tests/
cp tests/official.decTest arm32/tests/
cp tests/additional.decTest arm32/tests/

cp tests++/runtest arm32/tests/runtest_cxx
cp tests++/apitest arm32/tests/apitest_cxx
cp tests++/official.topTest arm32/tests/
cp tests++/additional.topTest arm32/tests/

tar cvzf arm32.tar.gz arm32

# Copy arm32.tar.gz to the target machine.
# Run the tests on the target machine (optional):
tar xvzf arm32.tar.gz
cd arm32/tests
./runtest official.decTest
./runtest additional.decTest

./runtest_cxx official.topTest
./runtest_cxx additional.topTest
./apitest_cxx

ARM64 (gcc)


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

tar xvf mpdecimal-4.0.0.tar.gz
cd mpdecimal-4.0.0

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

# Download the official tests (optional):
cd tests && ./gettests.sh && cd ..

# Build the tests (optional):
cd tests && make && cd ..
cd tests++ && make && cd ..

# Copy the tests (optional):
mkdir arm64/tests
cp tests/runtest arm64/tests
cp -a tests/testdata arm64/tests/
cp tests/official.decTest arm64/tests/
cp tests/additional.decTest arm64/tests/

cp tests++/runtest arm64/tests/runtest_cxx
cp tests++/apitest arm64/tests/apitest_cxx
cp tests++/official.topTest arm64/tests/
cp tests++/additional.topTest arm64/tests/

tar cvzf arm64.tar.gz arm64

# Copy arm64.tar.gz to the target machine.
# Run the tests on the target machine (optional):
tar xvzf arm64.tar.gz
cd arm64/tests
./runtest official.decTest
./runtest additional.decTest

./runtest_cxx official.topTest
./runtest_cxx additional.topTest
./apitest_cxx

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-4.0.0.tar.gz
cd mpdecimal-4.0.0

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.

WASM (emscripten)

The library build is supported, running the tests requires some manual work.


# Install the tool chain:
sudo apt-get install emscripten

# Build the static libraries (emscripten seems to ignore dynamic libs):
emconfigure ./configure --host=none --disable-shared
make

# Build and copy the C tests:
mkdir wasm
cd tests
./gettests.sh                                         # get official test files
cat official.decTest additional.decTest > all.decTest # a single argument is simpler

emcc -I../libmpdec -Wall -Wextra -Wno-unknown-pragmas -std=c99 -pedantic -O2 -s WASM=1 -s MINIFY_HTML=0 -o runtest.html runtest.c test.c ../libmpdec/libmpdec.a -lm --preload-file all.decTest --preload-file testdata

sed -i 's#.*var Module = {.*#var Module = {\narguments: ["all.decTest"],#' runtest.html
cp runtest.data runtest.wasm runtest.js runtest.html ../wasm
cd ..

tar cvzf wasm.tar.gz wasm


# Build and copy the C++ tests:
mkdir wasm_cxx
cd tests++
./gettests.sh                                         # get official test files
cat official.topTest additional.topTest > all.topTest # a single argument is simpler

em++ -pthread -I.. -I../libmpdec -I../libmpdec++ -Wall -Wextra -Wexit-time-destructors -std=c++11 -pedantic -DNDEBUG -O3 -s WASM=1 -s MINIFY_HTML=0 -o runtest.html runtest.cc test.cc ../libmpdec++/libmpdec++.a ../libmpdec/libmpdec.a -lm --preload-file all.topTest --preload-file testdata

em++ -pthread -I.. -I../libmpdec -I../libmpdec++ -Wall -Wextra -Wexit-time-destructors -std=c++11 -pedantic -DNDEBUG -O3 -s WASM=1 -s MINIFY_HTML=0 -o apitest.html apitest.cc test.cc ../libmpdec++/libmpdec++.a ../libmpdec/libmpdec.a -lm

sed -i 's#.*var Module = {.*#var Module = {\narguments: ["all.topTest"],#' runtest.html

cp runtest.data runtest.wasm runtest.worker.js runtest.js runtest.html apitest.wasm apitest.worker.js apitest.js apitest.html ../wasm_cxx
cd ..

tar cvzf wasm_cxx.tar.gz wasm_cxx

# Copy wasm.tar.gz to the webserver and unpack it in the webserver's root
# directory. If the webserver runs on 127.0.0.1, the tests will automatically
# run in the browser as follows:
#
# http://127.0.0.1/wasm/runtest.html
#
# NOTE: The provided console on the pages displays output only after
# the tests have finished, which can take 5 min on a slower machine.
#
# http://127.0.0.1/wasm_cxx/runtest.html
# http://127.0.0.1/wasm_cxx/apitest.html
#
# NOTE: The C++ tests do not run on at least some machines due to missing
# atomics etc. (Firefox).

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>