code: def get_ctypes_library(libname, packages, mode=None):
      
      libdirs = []
      # First try to get from LD_LIBRARY_PATH
      if "LD_LIBRARY_PATH" in os.environ:
          libdirs += os.environ["LD_LIBRARY_PATH"].split(":")
      # Next try to append via pkg_config
      try:
          libdirs += pkg_config_libdirs(packages)
      except ValueError:
          pass
  
      # Note that the function below can accept an empty list for libdirs, in which case
      # it will return None
      fullpath = get_libpath_from_dirlist(libname,libdirs)
  
      if fullpath is None:
          # This won't actually return a full-path, but it should be something
          # that can be found by CDLL
          fullpath = find_library(libname)
  
      if fullpath is None:
          # We got nothin'
          return None
      else:
          if mode is None:
              return ctypes.CDLL(fullpath)
          else:
              return ctypes.CDLL(fullpath,mode=mode)
docs: This function takes a library name, specified in architecture-independent fashion (i.e.
      omitting any prefix such as 'lib' or suffix such as 'so' or 'dylib' or version number) and
      a list of packages that may provide that library, and according first to LD_LIBRARY_PATH,
      then the results of pkg-config, and falling back to the system search path, will try to
      return a CDLL ctypes object.  If 'mode' is given it will be used when loading the library.