Skip to main content

Installation

STX is a header-only C++23 library that can be integrated into your project using various build systems. Choose the method that best fits your workflow.

Requirements

Minimum Requirements:
  • C++23-compliant compiler (Clang 16+, GCC 14+, or MSVC 19.34+)
  • Standard library only (no external dependencies)
For C++ Modules Support:
  • CMake 3.28+
  • Clang 16+ / GCC 14+ / MSVC 19.34+

CMake Integration

STX can be integrated using CMake in several ways. Choose the method that best fits your project structure.

Method 1: Add as Subdirectory

1

Add STX to your project

Clone or add STX as a git submodule:
git submodule add https://github.com/zethcxx/stx.git extern/stx
2

Update CMakeLists.txt

Add the following to your CMakeLists.txt:
# Add STX with traditional headers
add_subdirectory(extern/stx)

# Link to your target
target_link_libraries(your_target PRIVATE lbyte::stx)
3

Include in your code

#include <lbyte/stx.hpp>

using namespace lbyte::stx;

int main() {
    // Your code here
    return 0;
}
For automatic dependency management, use CMake’s FetchContent:
1

Configure FetchContent

Add to your CMakeLists.txt:
include(FetchContent)

FetchContent_Declare(
    stx
    GIT_REPOSITORY https://github.com/zethcxx/stx.git
    GIT_TAG        v2.0.0
)

FetchContent_MakeAvailable(stx)

target_link_libraries(${PROJECT_NAME} PRIVATE lbyte::stx)
2

Build your project

cmake -B build -S .
cmake --build build
Version Pinning: Always specify a git tag (like v2.0.0) for reproducible builds. See the releases page for available versions.

Xmake Integration

Since STX is not yet available on xrepo, you can use this workaround in your xmake.lua:
1

Define STX package

Add the following package definition to your xmake.lua:
package("zethcxx.stx")
    set_kind("library", { headeronly = true })
    set_urls("https://github.com/zethcxx/stx.git")

    add_versions( "v1.0.0", "v1.0.0" )
    add_versions( "v2.0.0", "v2.0.0" )

    add_configs( "use_modules", {
        builtin = false,
        default = false,
        type    = "boolean",
        description = "Use C++ Modules"
    })

    on_install( function( package )
        local configs = {}

        if package:config( "use_modules" ) then
            configs.use_modules = true
        end

        import("package.tools.xmake").install( package, configs )
    end)

    on_load( function( package )
        package:add("includedirs", "include")

        if package:config("use_modules") then
            package:add("cxxmodules", "modules/stx/*.cppm")
        end
    end)

    on_test( function (package)
        package:check_cxxsnippets({ test = "import lbyte.stx; int main() { return 0; }"},
            { configs = { languages = "c++23" }})
    end)
package_end()
2

Add dependency requirement

add_requires( "zethcxx.stx v2.0.0" )

target("your_target")
    set_kind("binary")
    add_files("src/*.cpp")
    add_packages("zethcxx.stx")
    set_languages("c++23")
3

Build

xmake

Manual Installation

For projects without a build system or for custom integration:
1

Download STX

Clone the repository:
git clone https://github.com/zethcxx/stx.git
2

Add include path

Add the include directory to your compiler’s include path:
# Using g++
g++ -std=c++23 -I/path/to/stx/include main.cpp -o main

# Using clang++
clang++ -std=c++23 -I/path/to/stx/include main.cpp -o main
3

Include the header

#include <lbyte/stx.hpp>

int main() {
    using namespace lbyte::stx;
    // Your code here
    return 0;
}

Troubleshooting

Missing Clang Resource Headers

When using C++ Modules with Clang, you might encounter errors like:
fatal error: 'stddef.h' file not found
fatal error: '__stddef_max_align_t.h' file not found
Solution: Export the Clang resource directory to your environment:
# For Clang 21 (adjust version as needed)
export CPLUS_INCLUDE_PATH="/usr/lib/clang/21/include/":$CPLUS_INCLUDE_PATH
This issue occurs when the compiler cannot locate its internal resource directory. The path may vary depending on your Clang installation.

CMake Version Error

If you see:
CMake Error: CMake 3.28 or higher is required
Solution: Update CMake or disable modules:
# Disable modules (use traditional headers)
set(LBYTE_STX_USE_MODULES OFF)
add_subdirectory(extern/stx)

Compiler Not C++23 Compatible

STX requires full C++23 support. If you encounter errors:
Ensure you’re using:
  • Clang 16+
  • GCC 14+
  • MSVC 19.34+
Check your compiler version:
# Clang
clang++ --version

# GCC
g++ --version

# MSVC
cl.exe

Verification

Verify your installation by building this simple test:
test.cpp
#include <lbyte/stx.hpp>
#include <print>

int main() {
    using namespace lbyte::stx;

    std::println("STX Version: {}.{}.{}",
        version.major,
        version.minor,
        version.patch);

    offset_t offset{0x1000};
    std::println("Offset: 0x{:x}", offset.get());

    return 0;
}
cmake -B build -S .
cmake --build build
./build/test
Expected output:
STX Version: 2.0.0
Offset: 0x1000

Next Steps

Quick Start

Learn the basics with hands-on examples

Core API

Explore core types and concepts

Memory API

Memory manipulation utilities

File System API

Binary file operations

Build docs developers (and LLMs) love