Releasing a Vulkan Loader library
Libraries that are loaded dynamically must be explicitly closed (released). To be able to use Vulkan in our application, we opened the Vulkan Loader (a vulkan-1.dll
library on Windows, or libvulkan.so.1
library on Linux). So, before we can close the application, we should free it.
How to do it...
On the Windows operating system family:
- Take the variable of type
HMODULE
namedvulkan_library
, in which the handle of a loaded Vulkan Loader was stored (refer to the Connecting with a Vulkan Loader library recipe). - Call
FreeLibrary( vulkan_library )
and provide thevulkan_library
variable in the only argument. - For safety reasons, assign the
nullptr
value to thevulkan_library
variable.
On the Linux operating system family:
- Take the variable of type
void*
namedvulkan_library
in which the handle of a loaded Vulkan Loader was stored (refer to Connecting with a Vulkan Loader library recipe). - Call
dlclose( vulkan_library )
, provide thevulkan_library
variable in the only argument. - For safety reasons, assign the
nullptr
value to thevulkan_library
variable.
How it works...
On the Windows operating system family, dynamic libraries are opened using the LoadLibrary()
function. Such libraries must be closed (released) by calling the FreeLibrary()
function to which the handle of a previously opened library must be provided.
On the Linux operating system family, dynamic libraries are opened using the dlopen()
function. Such libraries must be closed (released) by calling the dlclose()
function, to which the handle of a previously opened library must be provided:
#if defined _WIN32 FreeLibrary( vulkan_library ); #elif defined __linux dlclose( vulkan_library ); #endif vulkan_library = nullptr;
See also
- The recipe Connecting with a Vulkan Loader library in this chapter