dlinfo
dlinfo is a Python wrapper for libc's dlinfo (on Linux) and dyld_find (on macOS), providing a way to inspect dynamically loaded shared objects. The current version is 2.0.0. The project maintains an active development status with regular updates for Python compatibility and bug fixes, typically with releases tied to significant changes or Python version support.
Warnings
- breaking Version 2.0.0 removed compatibility with Python versions 3.5, 3.6, 3.7, and 3.8. Users on these older Python interpreters must remain on `dlinfo<2.0.0` or upgrade their Python environment to 3.9 or newer.
- breaking As of v2.0.0, the exception raised when the underlying `libc's dlinfo` function fails has changed from a generic `Exception` to a more specific `RuntimeError`. Update `except` blocks in your code accordingly.
- gotcha The library's core functionality relies on system-level C libraries (`libc's dlinfo` on Linux and `dyld_find` on macOS). This means its behavior is inherently platform-dependent and may not work on other operating systems like Windows without a POSIX compatibility layer, or might yield different results.
- gotcha The usage pattern involves direct interaction with Python's `ctypes` module to load shared libraries. Incorrect paths, non-existent libraries, or issues with `ctypes.util.find_library()` can lead to `OSError` or `AttributeError` when attempting to create `DLInfo` instances or access its properties.
Install
-
pip install dlinfo
Imports
- DLInfo
from dlinfo import DLInfo
Quickstart
import ctypes
import ctypes.util
from dlinfo import DLInfo
# Load the C standard library
# This will typically find 'libc.so.6' on Linux or 'libc.dylib' on macOS
lib_path = ctypes.util.find_library('c')
if lib_path is None:
print("Could not find the C standard library. This example may not run on your system.")
# Exit gracefully or raise an error depending on desired behavior
else:
lib = ctypes.cdll.LoadLibrary(lib_path)
# Create a DLInfo instance
dlinfo_instance = DLInfo(lib)
# Get the path of the loaded library
library_path = dlinfo_instance.path
print(f"Path of 'c' library: {library_path}")
# Example of getting SONAME (if available and applicable)
# On some systems, DLInfo.soname might return None if not explicitly set by the library
soname = dlinfo_instance.soname
if soname:
print(f"SONAME of 'c' library: {soname}")
else:
print("SONAME not explicitly available or not set for 'c' library.")