2

I am new and not familiar with Linux OS. The current OS I use is Ubuntu 19.10.

I was trying to build a SPPARKS (a software https://spparks.sandia.gov/index.html) executable by “make mpi”. The process got no error but a “shared library” file of spk_mpi instead of an “executable” file was produced.

I would appreciate any help from you. Thank you very much.

1 Answers1

1

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.

steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • Thanks very much for your kind reply. So could you tell me how I can know the correct version of gcc/g++ corresponding to OpenMPI (Open MPI 3.1.3 is on my PC)? And when and where should I use the command line that you proposed? "If you are using some other MPI implementation", so how do I know what MPI implementation I am using? Please forgive my ignorance. I haven't got a clear understanding of the entire system yet. – Yufan Zhao Feb 14 '20 at 00:28
  • @YufanZhao if you were able to successfully build it (aside from the PIC/PIE issue) with your system's default compilers, then I would suggest omitting the first two assignments and simply running OMPI_CFLAGS=-fno-pic OMPI_CXXFLAGS=-fno-pic OMPI_LDFLAGS=-no-pie make mpi (after first running make clean-all as I mentioned). You would run these commands in place of the suggested make mpi. – steeldriver Feb 14 '20 at 00:40
  • ... I only added OMPI_CC=gcc-5 OMPI_CXX=g++-5 because I experienced some build errors using the default gcc/g++ 7.4.0 on my system - and rather than investigating them, just guessed that they might go away with an older gcc/g++ version (since the source code appeared to be a couple of years old itself). – steeldriver Feb 14 '20 at 00:42
  • I followed your instructions, but after make with no build error, I got an "ELF 64-bit LSB pie executable" which is still a shared library file. I don't know what went wrong. – Yufan Zhao Feb 14 '20 at 01:01
  • Should I need to edit the low-level Makefile.mpi? – Yufan Zhao Feb 14 '20 at 01:36