This is really the same issue as discussed in these previous questions:
and the solution is essentially as mentioned in
The challenge for your particular situation is how to pass the appropriate compiler/linker options through the MPI compiler wrappers.
On my 18.04 system, with OpenMPI version indicated by
$ mpicc --showme:version
mpicc: Open MPI 2.1.1 (Language: C)
and explicitly selecting gcc/g++ version 5, I was able to get a traditional non-PIE executable using the following command line (broken up with \
line continuations for readibility):
OMPI_CC=gcc-5 OMPI_CXX=g++-5 \
OMPI_CFLAGS=-fno-pic OMPI_CXXFLAGS=-fno-pic OMPI_LDFLAGS=-no-pie \
make mpi
as confirmed using the file
command:
$ file spk_mpi
spk_mpi: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=284d76d1ca642cca833b31dfa028a7910e935600, not stripped
If you are using some other MPI implementation, you will need to figure out how to pass the appropriate flags for that.
NB you will probably need to run make clean-all
first in order to remove any objects that were previously compiled without the -fno-pic
flag.