code: def load_lib(exact_lib_names, lib_names, lib_dirs=None):
      """load_lib(exact_lib_names, lib_names, lib_dirs=None)
  
      Load a dynamic library.
  
      This function first tries to load the library from the given exact
      names. When that fails, it tries to find the library in common
      locations. It searches for files that start with one of the names
      given in lib_names (case insensitive). The search is performed in
      the given lib_dirs and a set of common library dirs.
  
      Returns ``(ctypes_library, library_path)``
      """
  
      # Checks
      assert isinstance(exact_lib_names, list)
      assert isinstance(lib_names, list)
      if lib_dirs is not None:
          assert isinstance(lib_dirs, list)
      exact_lib_names = [n for n in exact_lib_names if n]
      lib_names = [n for n in lib_names if n]
  
      # Get reference name (for better messages)
      if lib_names:
          the_lib_name = lib_names[0]
      elif exact_lib_names:
          the_lib_name = exact_lib_names[0]
      else:
          raise ValueError("No library name given.")
  
      # Collect filenames of potential libraries
      # First try a few bare library names that ctypes might be able to find
      # in the default locations for each platform.
      if SYSTEM_LIBS_ONLY:
          lib_dirs, lib_paths = [], []
      else:
          lib_dirs, lib_paths = generate_candidate_libs(
              lib_names, lib_dirs
          )
      lib_paths = exact_lib_names + lib_paths
  
      # Select loader
      if sys.platform.startswith("win"):
          loader = ctypes.windll
      else:
          loader = ctypes.cdll
  
      # Try to load until success
      the_lib = None
      errors = []
      for fname in lib_paths:
          try:
              the_lib = loader.LoadLibrary(fname)
              break
          except Exception as err:
              # Don't record errors when it couldn't load the library from an
              # exact name -- this fails often, and doesn't provide any useful
              # debugging information anyway, beyond "couldn't find library..."
              if fname not in exact_lib_names:
                  errors.append((fname, err))
  
      # No success ...
      if the_lib is None:
          if errors:
              # No library loaded, and load-errors reported for some
              # candidate libs
              err_txt = ["%s:\n%s" % (lib, str(e)) for lib, e in errors]
              msg = (
                  "One or more %s libraries were found, but "
                  + "could not be loaded due to the following errors:\n%s"
              )
              raise OSError(msg % (the_lib_name, "\n\n".join(err_txt)))
          else:
              # No errors, because no potential libraries found at all!
              msg = "Could not find a %s library in any of:\n%s"
              raise OSError(msg % (the_lib_name, "\n".join(lib_dirs)))
  
      # Done
      return the_lib, fname
  
imports: import os
  import sys
  import ctypes
label_desc: Use image node_id 3 for calling a global function with example usage: load_lib(exact_lib_names, lib_names, lib_dirs) and returns: the_lib,  fname