Why Use Modules?
Faster Compilation
Modules are compiled once and reused, reducing rebuild times
Better Isolation
No macro leakage or header pollution between translation units
Cleaner Imports
Replace
#include with clean import statementsImproved Build Scaling
Better parallelization and dependency tracking
System Requirements
Build System
- CMake: 3.28 or later
- Xmake: 2.8.0 or later
Compilers
| Compiler | Minimum Version | Notes |
|---|---|---|
| Clang | 16.0+ | Recommended for best modules support |
| GCC | 14.0+ | Requires -fmodules-ts flag |
| MSVC | 19.34+ (VS 2022 17.4+) | Windows only |
Available Modules
STX provides these module units:| Module | Import Statement | Description |
|---|---|---|
| stx | import lbyte.stx; | All STX utilities (recommended) |
| core | import lbyte.stx.core; | Core types and utilities |
| mem | import lbyte.stx.mem; | Memory utilities |
| time | import lbyte.stx.time; | Time and stopwatch utilities |
Setup Instructions
- CMake
- Xmake
Troubleshooting
Missing Clang Resource Headers
When using C++ Modules with Clang, you might encounter errors like:Export the include path
Add the Make this permanent by adding to your shell profile (
include subdirectory to your environment:~/.bashrc, ~/.zshrc, etc.)This issue is most common on Linux systems with manually installed Clang. System-provided Clang packages typically configure this automatically.
Module BMI Cache Issues
If you encounter stale module cache errors:Standard Library Module Conflicts
With Xmake, if you encounter issues with standard library modules:Compiler-Specific Notes
Clang
Clang
- Use Clang 16+ for stable modules support
- Clang 18+ recommended for best compatibility
- Ensure
libc++is available if using on Linux
GCC
GCC
- Requires GCC 14+ with
-fmodules-ts - Module support is experimental; prefer Clang if issues arise
- May require additional flags:
-std=c++23 -fmodules-ts
MSVC
MSVC
- Requires Visual Studio 2022 17.4+ (MSVC 19.34+)
- Enable in project properties: C/C++ → Language → Enable C++ Modules: Yes
- Ensure
/std:c++latestis set
Performance Considerations
First Build
Initial module compilation may take longer as BMI (Binary Module Interface) files are generated
Incremental Builds
Subsequent builds are significantly faster since modules are pre-compiled
Fallback to Header-Only
If you encounter persistent issues with modules, STX gracefully falls back to header-only mode:Next Steps
CMake Integration
CMake setup and configuration
Xmake Integration
Xmake setup and configuration