From 4aae11f8fb10a66219f23ffde1845fca51d035da Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 6 Oct 2021 08:46:20 -0400 Subject: [PATCH] port plugin loader to platform namespace --- examples/plugins/LAMMPSInterfaceCXX.cmake | 4 +++- src/PLUGIN/plugin.cpp | 28 +++++++---------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index 02f9159319..d52cf8f4e5 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -23,7 +23,9 @@ endfunction(validate_option) # LAMMPS C++ interface. We only need the header related parts. add_library(lammps INTERFACE) target_include_directories(lammps INTERFACE ${LAMMPS_HEADER_DIR}) - +if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) + target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) +endif() ################################################################################ # MPI configuration if(NOT CMAKE_CROSSCOMPILING) diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 270c9958f5..443fecc99f 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -25,12 +25,6 @@ #include #include -#ifdef _WIN32 -#include -#else -#include -#endif - namespace LAMMPS_NS { // list of plugin information data for loaded styles @@ -87,31 +81,28 @@ namespace LAMMPS_NS { #if defined(LMP_PLUGIN) int me = lmp->comm->me; -#if defined(WIN32) - lmp->error->all(FLERR,"Loading of plugins on Windows is not supported\n"); -#else // open DSO file from given path; load symbols globally - dlerror(); - void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); + platform::dlerror(); + void *dso = platform::dlopen(file); if (dso == nullptr) { if (me == 0) - utils::logmesg(lmp,"Open of file {} failed: {}\n",file,dlerror()); + utils::logmesg(lmp,"Open of file {} failed: {}\n",file,platform::dlerror()); return; } // look up lammpsplugin_init() function in DSO // function must have C bindings so there is no name mangling - dlerror(); - void *initfunc = dlsym(dso,"lammpsplugin_init"); + platform::dlerror(); + void *initfunc = platform::dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { - dlclose(dso); + platform::dlclose(dso); if (me == 0) utils::logmesg(lmp,"Plugin symbol lookup failure in file {}: {}\n", - file,dlerror()); + file,platform::dlerror()); return; } @@ -121,7 +112,6 @@ namespace LAMMPS_NS (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); -#endif #endif } @@ -410,9 +400,7 @@ namespace LAMMPS_NS -- dso_refcounter[handle]; if (dso_refcounter[handle] == 0) { -#ifndef WIN32 - dlclose(handle); -#endif + platform::dlclose(handle); } #endif }