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.
pip install dlinfoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load the C standard library using `ctypes`, create a `DLInfo` object, and retrieve the library's absolute file path and SONAME (if available). This is the primary usage pattern for `dlinfo`.
Upgrade Python to version 3.9 or later, or pin `dlinfo` to `<2.0.0`.
Change `except Exception:` to `except RuntimeError:` (or a more specific exception if applicable) for error handling related to `dlinfo` function failures.
Ensure your deployment environment is Linux or macOS. Be aware of potential platform-specific differences in behavior and available information.
Validate library paths and ensure the target shared library is accessible and correctly named for `ctypes.util.find_library()`. Add robust error handling around `ctypes` calls.
pip install dlinfo
Update your exception handling to catch `RuntimeError` instead of or in addition to a generic `Exception`.
```python
try:
# dlinfo usage
pass
except RuntimeError as e:
print(f"dlinfo operation failed: {e}")
```Ensure your deployment environment is Linux or macOS. The library is not designed to work on Windows without a POSIX compatibility layer.
Validate that the shared library you are trying to load exists and its path is correct and accessible. Add robust error handling around `ctypes` calls and `DLInfo` instantiation.
```python
import ctypes
import ctypes.util
from dlinfo import DLInfo
lib_name = 'c'
lib_path = ctypes.util.find_library(lib_name)
if lib_path is None:
print(f"Error: Could not find the '{lib_name}' library. Check if it's installed and in your system's library paths.")
else:
try:
lib = ctypes.cdll.LoadLibrary(lib_path)
dlinfo_instance = DLInfo(lib)
print(f"Library path: {dlinfo_instance.path}")
except OSError as e:
print(f"OSError loading library or creating DLInfo: {e}")
except AttributeError as e:
print(f"AttributeError accessing DLInfo properties: {e}")
```Upgrade your Python environment to version 3.9 or later, or if you must use an older Python version, pin the `dlinfo` library to a version less than 2.0.0 (e.g., `pip install dlinfo<2.0.0`).