{"id":529,"library":"librt","title":"Mypyc Runtime Library","description":"librt is the Mypyc runtime library, providing efficient C implementations of various Python standard library classes and functions. Mypyc leverages this library to produce faster C extensions when compiling Python code. It is primarily an internal dependency for `mypyc` and `mypy` (since version 1.19.0 for fixed-format cache serialization). The current version is 0.8.1, with development occurring in the main `mypy` repository and releases synced to the `librt` PyPI package.","status":"active","version":"0.8.1","language":"python","source_language":"en","source_url":"https://github.com/mypyc/librt","tags":["mypyc","runtime","performance","type-checking","c-extension"],"install":[{"cmd":"pip install librt","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"librt provides C implementations used by mypyc-generated extensions. While Python might theoretically allow importing internal parts (e.g., `librt.internal`), this is not part of its public API and can lead to unexpected issues or breaking changes. For example, `mypy` itself uses `librt` for cache serialization and deserialization, often through internal mechanisms rather than direct `import librt` in user code.","symbol":"librt","correct":"This library is primarily an internal runtime dependency for mypyc-compiled code and recent versions of mypy. Direct import of its internal symbols by end-user applications is generally not intended."}],"quickstart":{"code":"# librt is implicitly used by mypyc-compiled modules.\n# A typical quickstart involves using mypyc, which then utilizes librt.\n# First, ensure librt (and mypy, which includes mypyc) are installed.\n# pip install mypy mypyc\n\n# example_module.py\n# This module will be compiled by mypyc, which relies on librt at runtime.\n\ndef factorial(n: int) -> int:\n    result = 1\n    for i in range(1, n + 1):\n        result *= i\n    return result\n\nif __name__ == '__main__':\n    # In a real scenario, this would be compiled and imported as a C extension.\n    # For illustration, let's just run it as normal Python.\n    # To compile: mypyc example_module.py\n    # This creates a C extension (e.g., example_module.cpython-XYZ.so) that depends on librt.\n    print(f'Factorial of 5: {factorial(5)}')","lang":"python","description":"librt is a runtime library for code compiled with `mypyc`. Therefore, its 'quickstart' involves demonstrating how to use `mypyc` to compile Python code. The compiled code will then depend on `librt` at runtime. The example shows a simple Python function that `mypyc` could compile, implicitly leveraging `librt`'s optimizations."},"warnings":[{"fix":"Avoid using librt-dependent components in PyPy environments or configure CI to exclude librt-related checks/builds for PyPy.","message":"librt does not officially support PyPy. If your project targets PyPy and has `librt` as a dependency (e.g., through `mypy` for type checking), you may need to skip it in your CI matrix for PyPy environments.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure `librt` is kept in sync with the `mypyc` version used for compilation. Pinning exact versions of `librt` and `mypyc` is recommended, especially in production environments or when distributing `mypyc`-compiled code.","message":"librt's Application Binary Interface (ABI) is not explicitly versioned, and changes to it can lead to compatibility issues with `mypyc`-compiled extensions. This can cause breakage if `librt` is updated independently of `mypyc` or the compiled application.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Treat librt as an implementation detail of mypyc. Do not directly import or use symbols from `librt` in your application code; instead, rely on the behavior of `mypyc`-compiled modules.","message":"librt is primarily an internal runtime component. Direct imports or reliance on its internal API in user-facing Python code are discouraged, as these interfaces are subject to change without standard deprecation warnings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If upgrading `mypy` to 1.19.0 or newer, ensure `librt` is installed alongside it. For older `mypy` versions, `librt` is not required for cache functionality.","message":"Mypy 1.19.0 introduced `librt` as a dependency for its fixed-format cache serialization. Older versions of `mypy` (before 1.19.0) did not require `librt` for this purpose, relying instead on JSON-based caching.","severity":"deprecated","affected_versions":"<1.19.0 (mypy)"}],"env_vars":null,"last_verified":"2026-05-12T14:41:19.954Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure that `-lrt` is added to your linker flags when compiling, typically at the end of the command. For example, `gcc -o myprogram myprogram.c -lrt`.","cause":"This error occurs during compilation or linking of C/C++ code (or Mypyc-compiled extensions that use C) when functions like `shm_open` or `timer_create` from the POSIX Realtime Extensions library (`librt`) are used, but the linker is not explicitly told to link against `librt`, or cannot find it.","error":"undefined reference to 'shm_open'"},{"fix":"On Linux, ensure the `librt` development package is installed (e.g., `libc6-dev` or `glibc-devel`). If cross-compiling, verify that the target environment's `librt` is correctly configured and accessible in the toolchain's library paths. On Ubuntu, a common fix for `librt.so` not being found is to create a symbolic link: `sudo ln -s /lib/x86_64-linux-gnu/librt.so.1 /usr/lib/x86_64-linux-gnu/librt.so`.","cause":"This linking error indicates that the compiler or linker (often ARM's `armclang` or similar cross-compilers) cannot locate the `librt` library file on the system, even if the `-lrt` flag is provided.","error":"Fatal error: L6450U: Cannot find library rt."},{"fix":"This issue typically requires a patch to the `librt` build system to recognize and correctly handle the `ibmxl` compiler. Developers may need to check the `mypyc/librt` GitHub repository for updates or contribute a fix for the specific compiler environment.","cause":"This error occurs during `librt` installation (often as a dependency of `mypy` version 1.19.x and later) on systems using the IBM XL compiler, because `librt`'s `build_setup.py` script does not have explicit support or configuration for this specific compiler type.","error":"KeyError: 'ibmxl'"},{"fix":"Ensure you have a C compiler installed (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual Studio C++ build tools on Windows). For less common platforms like MSYS2, check if pre-built wheels become available, or if there are specific environment setup instructions for compiling C extensions. You might also try installing `mypy` using a Python version for which pre-built `librt` wheels are generally available.","cause":"This common installation error occurs when `pip` attempts to install `librt` (or `mypy` which depends on it) and cannot compile the C extension due to missing build tools, incompatible compiler environments, or the unavailability of pre-built wheels for the specific operating system and Python version (e.g., on MSYS2/UCRT64/MinGW64 environments).","error":"ERROR: Failed building wheel for librt\nFailed to build librt\nERROR: Could not build wheels for librt"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}