port plugin loader to platform namespace
This commit is contained in:
@ -23,7 +23,9 @@ endfunction(validate_option)
|
|||||||
# LAMMPS C++ interface. We only need the header related parts.
|
# LAMMPS C++ interface. We only need the header related parts.
|
||||||
add_library(lammps INTERFACE)
|
add_library(lammps INTERFACE)
|
||||||
target_include_directories(lammps INTERFACE ${LAMMPS_HEADER_DIR})
|
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
|
# MPI configuration
|
||||||
if(NOT CMAKE_CROSSCOMPILING)
|
if(NOT CMAKE_CROSSCOMPILING)
|
||||||
|
|||||||
@ -25,12 +25,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace LAMMPS_NS
|
namespace LAMMPS_NS
|
||||||
{
|
{
|
||||||
// list of plugin information data for loaded styles
|
// list of plugin information data for loaded styles
|
||||||
@ -87,31 +81,28 @@ namespace LAMMPS_NS
|
|||||||
{
|
{
|
||||||
#if defined(LMP_PLUGIN)
|
#if defined(LMP_PLUGIN)
|
||||||
int me = lmp->comm->me;
|
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
|
// open DSO file from given path; load symbols globally
|
||||||
|
|
||||||
dlerror();
|
platform::dlerror();
|
||||||
void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL);
|
void *dso = platform::dlopen(file);
|
||||||
if (dso == nullptr) {
|
if (dso == nullptr) {
|
||||||
if (me == 0)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// look up lammpsplugin_init() function in DSO
|
// look up lammpsplugin_init() function in DSO
|
||||||
// function must have C bindings so there is no name mangling
|
// function must have C bindings so there is no name mangling
|
||||||
|
|
||||||
dlerror();
|
platform::dlerror();
|
||||||
void *initfunc = dlsym(dso,"lammpsplugin_init");
|
void *initfunc = platform::dlsym(dso,"lammpsplugin_init");
|
||||||
if (initfunc == nullptr) {
|
if (initfunc == nullptr) {
|
||||||
dlclose(dso);
|
platform::dlclose(dso);
|
||||||
|
|
||||||
if (me == 0)
|
if (me == 0)
|
||||||
utils::logmesg(lmp,"Plugin symbol lookup failure in file {}: {}\n",
|
utils::logmesg(lmp,"Plugin symbol lookup failure in file {}: {}\n",
|
||||||
file,dlerror());
|
file,platform::dlerror());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +112,6 @@ namespace LAMMPS_NS
|
|||||||
|
|
||||||
(*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso,
|
(*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso,
|
||||||
(void *)&plugin_register);
|
(void *)&plugin_register);
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,9 +400,7 @@ namespace LAMMPS_NS
|
|||||||
|
|
||||||
-- dso_refcounter[handle];
|
-- dso_refcounter[handle];
|
||||||
if (dso_refcounter[handle] == 0) {
|
if (dso_refcounter[handle] == 0) {
|
||||||
#ifndef WIN32
|
platform::dlclose(handle);
|
||||||
dlclose(handle);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user