https://mooseframework.inl.gov
DynamicLibraryLoader.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "DynamicLibraryLoader.h"
11 #include "MooseUtils.h"
12 
13 DynamicLibraryLoader::DynamicLibraryLoader(const std::string & library_file)
14  : _library_file(library_file)
15 {
16  MooseUtils::checkFileReadable(_library_file, false, /*throw_on_unreadable=*/true);
17 #ifdef LIBMESH_HAVE_DLOPEN
18  _handle = dlopen(_library_file.c_str(), RTLD_LAZY);
19  if (!_handle)
20  mooseError("Failed to load library '", _library_file, "' in DynamicLibraryLoader: ", dlerror());
21 
22  dlerror();
23 #else
24  // support for the POSIX function 'dlopen' to dynamically load libraries is missing
25  mooseError("Dynamic library loading is not supported on this operating system.");
26 #endif
27 }
28 
30 {
31 #ifdef LIBMESH_HAVE_DLOPEN
32  dlclose(_handle);
33 #endif
34 }
void mooseError(Args &&... args)
void * _handle
Library handle returned by dlopen.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
const std::string _library_file
Library file name.
DynamicLibraryLoader(const std::string &library_file)