code: def _load_shared_library(lib_name: str) -> Optional[CDLL]:
      # In Conda environments, we always expect native libraries to be part of the
      # environment, so we skip the default lookup rules of the dynamic linker.
      if not "CONDA_PREFIX" in environ:
          try:
              # Use the global namespace to ensure that all modules use the same
              # library instance.
              return CDLL(lib_name, mode=RTLD_GLOBAL)
          except OSError:
              pass
  
          # On macOS, we also explicitly check the well-known Homebrew locations.
          if platform.system() == "Darwin":
              for brew_path in [
                  "/usr/local/lib",
                  "/opt/homebrew/lib",
                  "~/homebrew",
              ]:
                  path = Path(brew_path, lib_name).expanduser()
  
                  try:
                      return CDLL(str(path), mode=RTLD_GLOBAL)
                  except OSError:
                      pass
  
      if site.ENABLE_USER_SITE:
          site_packages = [site.getusersitepackages()]
      else:
          site_packages = []
  
      site_packages += site.getsitepackages()
  
      # If the system does not have the library, try to load it from the site
      # packages of the current Python environment.
      for packages_dir in site_packages:
          lib_path = Path(packages_dir).parent.parent.joinpath(lib_name)
  
          try:
              return CDLL(str(lib_path), mode=RTLD_GLOBAL)
          except OSError:
              pass
  
      return None
  
file_path: fairseq2/native/python/src/fairseq2n/__init__.py
imports: import platform
  import site
  from ctypes import CDLL, RTLD_GLOBAL
  from os import environ
  from pathlib import Path
  from typing import List, Optional, Tuple
  from fairseq2n.config import _CUDA_VERSION, _SUPPORTS_CUDA, _SUPPORTS_IMAGE, _TORCH_VARIANT, _TORCH_VERSION
label_desc: Use image node_id 12 for calling a global function with example usage: _load_shared_library(lib_name) and returns: None, CDLL, CDLL, CDLL