Elements  5.12.0
A C++ base framework for the Euclid Software.
ThisModule.cpp
Go to the documentation of this file.
1 
23 
24 #include <cstddef>
25 #include <dlfcn.h>
26 
27 #include "ElementsKernel/FuncPtrCast.h" // for FuncPtrCast
28 #include "ElementsKernel/ModuleInfo.h" // for ModuleInfo
29 
30 namespace Elements {
31 namespace System {
32 
33 
35  static ModuleInfo this_module;
36  if (this_module.isEmpty()) {
37  void* handle = ::dlopen(nullptr, RTLD_LAZY);
38  if (nullptr != handle) {
39  void* func = ::dlsym(handle, "main");
40  if (nullptr != func) {
41  this_module = ModuleInfo(FuncPtrCast<void*>(func));
42  }
43  }
44  }
45 
46  return this_module;
47 }
48 
49 
50 } // namespace System
51 } // namespace Elements
defines a Small helper function that allows the cast from void * to function pointer
OS specific details to access at run-time the module configuration of the process.
header to get the module info statically
ELEMENTS_API const ModuleInfo & getThisExecutableInfo()
Definition: ThisModule.cpp:34