diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index fc427acdc9..ec4a9c2eb7 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -617,15 +617,12 @@ foreach(PKG_WITH_INCL CORESHELL QEQ OPENMP DPD-SMOOTH KOKKOS OPT INTEL GPU) endforeach() if(PKG_PLUGIN) - if(BUILD_SHARED_LIBS) - target_compile_definitions(lammps PRIVATE -DLMP_PLUGIN) - else() - message(WARNING "Plugin loading will not work unless BUILD_SHARED_LIBS is enabled") - endif() - # link with -ldl or equivalent for plugin loading; except on Windows - if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - target_link_libraries(lammps PRIVATE ${CMAKE_DL_LIBS}) - endif() + target_compile_definitions(lammps PRIVATE -DLMP_PLUGIN) +endif() + +# link with -ldl or equivalent for plugin loading; except on Windows +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + target_link_libraries(lammps PRIVATE ${CMAKE_DL_LIBS}) endif() ###################################################################### diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index 7995ddc369..5372dffc83 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -65,10 +65,8 @@ only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. Plugins are not available on Windows. -For the loading of plugins to work the LAMMPS library must be -:ref:`compiled as a shared library `. If plugins -access functions or classes from a package, LAMMPS must have -been compiled with that package included. +If plugins access functions or classes from a package, LAMMPS must +have been compiled with that package included. Plugins are dependent on the LAMMPS binary interface (ABI) and particularly the MPI library used. So they are not guaranteed diff --git a/src/MAKE/MACHINES/Makefile.cygwin b/src/MAKE/MACHINES/Makefile.cygwin index 3d4a50a8ea..1af9cfe802 100644 --- a/src/MAKE/MACHINES/Makefile.cygwin +++ b/src/MAKE/MACHINES/Makefile.cygwin @@ -65,6 +65,9 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, but should be empty on Windows) + +override DYN_LIB = # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index 42f48b4e2c..cf796be69b 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section diff --git a/src/MAKE/Makefile.serial b/src/MAKE/Makefile.serial index b527919147..6dd8415ea9 100644 --- a/src/MAKE/Makefile.serial +++ b/src/MAKE/Makefile.serial @@ -65,6 +65,11 @@ JPG_INC = JPG_PATH = JPG_LIB = +# library for loading shared objects (defaults to -ldl, should be empty on Windows) +# uncomment to change the default + +# override DYN_LIB = + # --------------------------------------------------------------------- # build rules and dependencies # do not edit this section @@ -74,7 +79,7 @@ include Makefile.package EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC) EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH) -EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) +EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB) $(DYN_LIB) EXTRA_CPP_DEPENDS = $(PKG_CPP_DEPENDS) EXTRA_LINK_DEPENDS = $(PKG_LINK_DEPENDS) diff --git a/src/Makefile b/src/Makefile index 7f02c1e84b..2d651c4986 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,6 +2,7 @@ SHELL = /bin/bash PYTHON = python +DYN_LIB = -ldl #.IGNORE: @@ -400,14 +401,14 @@ ifeq ($(mode),static) @cd $(objdir); \ $(MAKE) $(MFLAGS) "OBJ = $(OBJLIB)" "INC = $(INC)" "SHFLAGS =" \ "LMPLIB = $(ARLIB)" "ARLIB = $(ARLIB)" "SHLIB = $(SHLIB)" \ - "LMPLINK = $(LMPLINK)" "EXE = ../$(EXE)" ../$(EXE) + "LMPLINK = $(LMPLINK)" "DYN_LIB = $(DYN_LIB)" "EXE = ../$(EXE)" ../$(EXE) @ln -s $(ARLIB) $(ARLINK) endif ifeq ($(mode),shared) @cd $(objdir); \ $(MAKE) $(MFLAGS) "OBJ = $(OBJLIB)" "INC = $(INC)" \ "LMPLIB = $(SHLIB)" "ARLIB = $(ARLIB)" "SHLIB = $(SHLIB)" \ - "LMPLINK = $(LMPLINK)" "EXE = ../$(EXE)" ../$(EXE) + "LMPLINK = $(LMPLINK)" "DYN_LIB = $(DYN_LIB)" "EXE = ../$(EXE)" ../$(EXE) @ln -s $(SHLIB) $(SHLINK) endif # backward compatibility