"Could NOT find MPI (missing: MPI_C_FOUND C)" CMake error

Hi,

I am trying to build LAMMPS with the VTK package. I am getting this error when running cmake:

CMake Error at /usr/local/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)

      Reason given by package: MPI component 'C' was requested, but language C is not enabled.  

Call Stack (most recent call first):
  /usr/local/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.31/Modules/FindMPI.cmake:1842 (find_package_handle_standard_args)
  /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/VTK-vtk-module-find-packages.cmake:397 (find_package)
  /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake:150 (include)
  Modules/Packages/VTK.cmake:1 (find_package)
  CMakeLists.txt:585 (include)

I’ve installed VTK and Qt by running:

sudo apt-get install libvtk9-dev
sudo apt-get install qtdeclarative5-dev
sudo apt-get install qtbase5-dev

CMake version: cmake version 3.31.1
OpenMPI version: mpiexec (OpenRTE) 4.1.2
Ubuntu version: 22.04.5 LTS

Hi @Michele_Pellegrino

you need libopenmpi-dev

Best,

libopenmpi-dev is already the newest version (4.1.2-2ubuntu1).

Then you probably needs something like this in your project:

project(project VERSION 0.1 LANGUAGES C CXX)

Yes, that could be the solution. However it’s not really “my” project and I wouldn’t want to hack into the CMake files of LAMMPS as I have limited developer experience. I’ll try, but I would really prefer another solution, if exists.

Thank you.

Then this may be a LAMMPS issue ?

Could be, however I haven’t found any other LAMMPS user reporting a similar issue. It seems mostly related to VTK installation (not just on LAMMPS).

Ok it worked! Thank you.

A better solution may be to add enable_language(C) in the VTK.cmake file (this was suggested by a LAMMPS developer).

1 Like

wdyt @ben.boeckel ?

Eh…I don’t think so. enable_language should not be called from function and there’s nothing saying find_package(VTK) can’t be there. Users also might not be expecting C bits to be used suddenly. I feel like something like:

# Require MPI support exist.
if (TARGET VTK::mpi AND
    # Require there be a reason we were looking for it.
    DEFINED VTK_mpi_FOUND AND
    # Require that finding it failed.
    NOT VTK_mpi_FOUND)
  # Detect if the C language is around.
  if (NOT CMAKE_C_COMPILER_WORKS)
    list(APPEND VTK_mpi_NOT_FOUND_MESSAGE
      "The C language is not available; MPI needs C enabled in order to be detected")
  endif ()
endif ()

(adapted for vtk-config’s…unqiue variable naming mechanisms).