LAMMPS installation on M2 macbook pro

Hi! First time user of LAMMPS. I was able to install and use the basic version of LAMMPS using cmake and source code from github branch develop.

Now I am trying to compile and install using the most.cmake file. I keep getting the error, ‘ld: library not found for -lgfortran’. The library libgfortran.a does exist at /usr/local/gfortran/lib/. Also note that the code uses the compiler found at a slightly different location, /usr/local/bin. So I do not know if the issue is due to the code trying to find the libraries in a different location?

So far I tried this, but none worked

  1. Added a symlink at /usr/local/lib/ from /usr/local/gfortran/lib/
  2. Do not know if it helps but added export LD_LIBRARY_PATH=:/usr/local:$LD_LIBRARY_PATH to .bashrc file hoping the code can look at inside folder path for the shared libraries?
  3. Simply using brew install gfortran doesn’t build the libraries only the executable gfortran on macOS Ventura.

Anyway I can specify the path to these libraries while using cmake? I know one can do that using -L in usual makefile?

Maybe I am over complicating it, please let me know if you all have any suggestions. Thank you!

Well, can you use the gfortran Fortran compiler to compile (simple) fortran code?

To be able to help you, we need more details. The exact commands you were running with cmake. …and some more context for the error.

Not much of LAMMPS requires fortran these days, so as a workaround, you can try disabling the fortran compiler for now by adding -D CMAKE_Fortran_COMPILER="" to your cmake command.

No that the -D with empty “” did not work. It gave the error,

CMake Error at Modules/Packages/KIM.cmake:37 (enable_language):
No CMAKE_Fortran_COMPILER could be found.

Tell CMake where to find the compiler by setting either the environment
variable “FC” or the CMake cache entry CMAKE_Fortran_COMPILER to the full
path to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
CMakeLists.txt:525 (include)

The exact CMake command I am using is,
cmake -C …/cmake/presets/most.cmake -D WITH_JPEG=yes -D WITH_PNG=yes -D WITH_FFMPEG=yes -D PKG_KIM=on -D BUILD_SHARED_LIBS=on …/cmake

The only error message I receive after the line [100%] Linking CXX shared library liblammps.dylib,

ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [liblammps.0.dylib] Error 1
make[1]: *** [CMakeFiles/lammps.dir/all] Error 2
make: *** [all] Error 2

You didn’t answer whether your fortran compiler is actually functional. It seems that not.

The issue is triggered by -D PKG_KIM=on. It is not that the OpenKIM package support by itself is written in fortran, but rather that some of the the OpenKIM compute kernels require a working fortran compiler. So you would also have to skip using KIM for now until you have fixed your fortran compiler installation. You would have to discuss with the OpenKIM folks about how to address this issue, in case your fortran compiler is usable.

Sorry about that! Yes the fortran compiler works. I tested out few simple examples. Also, removing the PKG_KIM=on did the trick! Thank you for the quick reply and resolve!

Please also note the error with disabling fortran indicates that you are using the automated KIM-API download. That is not a good idea if you plan to use OpenKIM seriously. Instead, your should first do a full install of the KIM-API so you also have the management tools and more available to you.
If CMake can find that local installation of the KIM-API, it will use that and then there should be no problems (unless they already happen during the KIM-API installation).

1 Like