How to use lammps plugin

Dear users,

I would like to use the plugin GitHub - lammps/lammps-plugins: Collection of LAMMPS plugins. I have compiled standard version of lammps with PLUGIN pagckage with “make mpi” and compile the plugin with instructions. I found there is library ending with .so in the lammps-plugins/build folder. In my input, I used "plugin load path/to/.so". however, I got the error like “Unrecognized fix style”. How to properly use the lammps-plugin?

Plugins are meant for when people want to distribute add-on binaries (or cannot distribute binaries that are linked to certain source code due to licensing conflicts). For example, the ACE library for the ML-PACE package has a license that is not compatible with the LAMMPS license. But when compiling the ML-PACE package as a plugin, it is the user that does the linking and not the person distributing both, since those are separate binaries.

When you compile LAMMPS from source, though, you can just copy the corresponding source files e.g. fix_xxx.h and fix_xxx.cpp or pair_yyy.h and pair_yyy.cpp to the src folder of your LAMMPS sources. recompile LAMMPS and those should be included. You can easily check with ./lmp_mpi -h whether you see the added style(s).

Update:
When compiling the plugin, it is crucial to use the exact same compilation settings, e.g. the settings for integer sizes, exceptions, MPI on/off etc. otherwise there will be failures to load the plugin.
Example: the plugin was compiled with -D BUILD_MPI=on and -DLAMMPS_SIZES=smallsmall, but the LAMMPS executable with -DBUILD_MPI=on and -DLAMMPS_SIZES=smallbig (the default). Then the plugin cannot load:

LAMMPS (2 Aug 2023 - Development - patch_2Aug2023-64-g8eb7f56491)
  using 1 OpenMP thread(s) per MPI task
plugin load /home/akohlmey/compile/lammps-plugins/build-bfield/bfieldplugin.so
Open of file /home/akohlmey/compile/lammps-plugins/build-bfield/bfieldplugin.so failed: /home/akohlmey/compile/lammps-plugins/build-bfield/bfieldplugin.so: undefined symbol: _ZN9LAMMPS_NS6Modify15addstep_computeEi
Total wall time: 0:00:11

This is because the size of the integer argument in the function Modify::addstep_compute() is 32-bit in one case and 64-bit in the other. Compiling with -DLAMMPS_SIZES=smallbig consistently gives:

$ ./lmp 
LAMMPS (2 Aug 2023 - Development - patch_2Aug2023-64-g8eb7f56491)
  using 1 OpenMP thread(s) per MPI task
plugin load /home/akohlmey/compile/lammps-plugins/build-bfield/bfieldplugin.so
Loading plugin: fix bfield plugin v1.0 by Axel Kohlmeyer ([email protected])
plugin list
Currently loaded plugins
   1: fix style plugin bfield
Total wall time: 0:05:27