[petsc-users] Cross compilation of PETSc using MXE

Lars Odsæter lars.odsater at sintef.no
Fri Jan 17 06:00:01 CST 2020


Dear PETSc users,

First, thanks to the developers for your great effort with the PETSc library, which I have benefited from several times.

I want to share with you that I recently was able to cross compile PETSc with the MXE (mxe.cc) cross compiler, and then link it into an application (also built with the mxe compiler) to produce an executable that I successfully ran on my Windows computer. In doing this I realized that there is very little documentation of this on the web, so maybe others could benefit from my approach. It contains a few hacks that might be solved more elegant, but that is probably out of may range.

First, I installed the mxe cross compiler following the tutorial (mxe.cc/#tutorial<https://mxe.cc/#tutorial>):

git clone https://github.com/mxe/mxe.git
make cc
make blas lapack
export PATH=~/code/mxe/usr/bin:$PATH

Then I compiled PETSc (3.11.3 tarball):

wget http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.11.3.tar.gz
gunzip -c petsc-3.11.3.tar.gz | tar -xof -
cd petsc-3.11.3/
./configure PETSC_ARCH=arch-mxe-static \
  --with-mpi=0 --host=i686-w64-mingw32.static \
  --enable-static --disable-shared \
  --with-cc=i686-w64-mingw32.static-gcc \
  --with-cxx=i686-w64-mingw32.static-g++ \
  --with-fc=i686-w64-mingw32.static-gfortran \
  --with-ld=i686-w64-mingw32.static-ld \
  --with-ar=i686-w64-mingw32.static-ar \
  --with-pkg-config=i686-w64-mingw32.static-pkg-config \
  --with-batch --known-64-bit-blas-indices

Next, I did the reconfigure step that was explained in the output from the call to configure:

* copy 'conftest-arch-mxe-static' to your Windows machine
* Rename it with extension '.exe'
* Run the application in Windows. This generates 'reconfigure-arch-mxe-static.py'
* Copy 'reconfigure-arch-mxe-static.py' back to the Linux machine
* Run the python script:

python reconfigure-arch-mxe-static.py

Now, 'make all' failed to compile, but I did two hacks to mitigate it:

1) In  '~/code/petsc-3.11.3/arch-mxe-static/include/petscconf.h' include the following lines:
#ifndef PETSC_HAVE_DIRECT_H
#define PETSC_HAVE_DIRECT_H 1
#endif

2) In ~/code/petsc-3.11.3/src/sys/error/fp.c, comment out line 405-406:
// elif defined PETSC_HAVE_XMMINTRIN_H
// _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT | _MM_MASK_UNDERFLOW);

After this 'make all' ran successfully.
I was finally able to compile my code (linking PETSc) following step 5 of the mxe tutorial: mxe.cc/#tutorial<https://mxe.cc/#tutorial>
Then, simply copy to Windows and double-click.


Best regards,

Lars Hov Odsæter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200117/67b36c06/attachment-0001.html>


More information about the petsc-users mailing list