I would like to write a LAMMPS plugin. To learn how plugins work, I decided to compile the example plugins and load them with a LAMMPS binary compiled on the same system (Fedora Linux 39). However, when I e.g. issue the command plugin load helloplugin.so
, I always get the error Open of file helloplugin.so failed: helloplugin.so: cannot open shared object file: No such file or directory
. Now, this error seems very self-explanatory, and maybe I’m being stupid, but I am sure that the file is there and that the working directory is correct. If I install LAMMPS from conda-forge, I get the same error.
Here are the steps that reproduce the error for me:
git clone https://github.com/lammps/lammps.git
cd lammps
mkdir build
cd build
cmake ../cmake/ -DPKG_PLUGIN=yes
cmake --build . -j 8
cd ../examples/plugins/
mkdir build
cd build
cmake ..
cmake --build . -j 8
../../../build/lmp
plugin load helloplugin.so
# Open of file helloplugin.so failed: helloplugin.so: cannot open shared object file: No such file or directory
The plugin files are all there though:
(lammps_src) [niklas@nxps build]$ ls -al
total 264
drwxr-xr-x. 1 niklas niklas 234 24. Feb 10:25 ./
drwxr-xr-x. 1 niklas niklas 824 24. Feb 10:23 ../
-rw-r--r--. 1 niklas niklas 18882 24. Feb 10:23 CMakeCache.txt
drwxr-xr-x. 1 niklas niklas 516 24. Feb 10:24 CMakeFiles/
-rw-r--r--. 1 niklas niklas 1665 24. Feb 10:23 cmake_install.cmake
-rwxr-xr-x. 1 niklas niklas 23360 24. Feb 10:24 helloplugin.so*
-rw-r--r--. 1 niklas niklas 369 24. Feb 10:45 log.lammps
-rw-r--r--. 1 niklas niklas 16656 24. Feb 10:23 Makefile
-rwxr-xr-x. 1 niklas niklas 66736 24. Feb 10:24 morse2plugin.so*
-rwxr-xr-x. 1 niklas niklas 45088 24. Feb 10:24 nve2plugin.so*
-rwxr-xr-x. 1 niklas niklas 77408 24. Feb 10:24 zero2plugin.so*
Here is the cmake output for LAMMPS:
(lammps_src) [niklas@nxps build]$ cmake ../cmake/ -DPKG_PLUGIN=yes
-- The CXX compiler identification is GNU 13.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.43.0")
-- Running check for auto-generated files from make-based build system
-- Checking for module 'mpi-cxx'
-- Package 'mpi-cxx', required by 'virtual:world', not found
-- Looking for C++ include omp.h
-- Looking for C++ include omp.h - found
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5") found components: CXX
-- Found GZIP: /usr/bin/gzip
-- Found FFMPEG: /usr/bin/ffmpeg
-- Looking for C++ include cmath
-- Looking for C++ include cmath - found
-- Generating style headers...
-- Generating package headers...
-- Generating lmpinstalledpkgs.h...
-- Found Python3: /usr/bin/python3.12 (found version "3.12.1") found components: Interpreter
-- Could NOT find ClangFormat (missing: ClangFormat_EXECUTABLE) (Required is at least version "8.0")
-- The following tools and libraries have been found and configured:
* Git
* OpenMP
* Python3
-- <<< Build configuration >>>
LAMMPS Version: 20240207 patch_7Feb2024_update1-89-g6c3c724f9c
Operating System: Linux Fedora 39
CMake Version: 3.28.3
Build type: RelWithDebInfo
Install path: /home/niklas/.local
Generator: Unix Makefiles using /usr/bin/gmake
-- Enabled packages: PLUGIN
-- <<< Compilers and Flags: >>>
-- C++ Compiler: /usr/bin/c++
Type: GNU
Version: 13.2.1
C++ Flags: -O2 -g -DNDEBUG
Defines: LAMMPS_SMALLBIG;LAMMPS_MEMALIGN=64;LAMMPS_OMP_COMPAT=4;LAMMPS_GZIP;LAMMPS_FFMPEG;LMP_PLUGIN
-- <<< Linker flags: >>>
-- Executable name: lmp
-- Static library flags:
-- Configuring done (3.6s)
-- Generating done (0.1s)
-- Build files have been written to: /home/niklas/src/lammps/build
And here is the cmake output for the plugins:
(lammps_src) [niklas@nxps build]$ cmake ..
-- The CXX compiler identification is GNU 13.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for module 'mpi-cxx'
-- Package 'mpi-cxx', required by 'virtual:world', not found
-- Looking for C++ include omp.h
-- Looking for C++ include omp.h - found
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /home/niklas/src/lammps/examples/plugins/build
Why can I not load the plugins? Am I missing something obvious?