Resolving 'mpicc: No such file or directory' Compilation Error
Root Cause and Solutions
Missing MPI Development Packages
The error occurs when MPI compiler wrappers are not available in the system. Check if MPI libraries are installed:
rpm -qa | grep -i mpi
Install the required packages using:
# Option 1: OpenMPI
yum install openmpi openmpi-devel
# Option 2: MPICH
yum install mpich mpich-devel
The -devel packages are esential as they provide the compiler wrappers like mpicc, while base packages only include runtime components such as mpirun.
Path Configuration Issues
After installation, MPI executables are typically located in /usr/lib64/openmpi/bin or /usr/lib64/mpich/bin. These directory are not automatically added to system PATH during installation.
To resolve this:
# Temporary solution
export PATH=/usr/lib64/openmpi/bin:$PATH
# Permanent solution
echo 'export PATH=/usr/lib64/openmpi/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Anaconda Environment Conflicts
When Anaconda is installed, its bin directory often takes precedence in PATH, potentially overriding system MPI installations. Even if Anaconda includes mpicc, it may not function correctly due to missing dependencies or incorrect configurations.
Verify which mpicc is being used:
which mpicc
whereis mpicc
To prioritize system MPI over Anaconda:
# Reorder PATH to prioritize system MPI
export PATH=/usr/lib64/openmpi/bin:$PATH:/opt/anaconda3/bin
This ensures the functional system MPI compiler wrapper is used instead of the non-working Anaconda version.