Skip to main content
Learn how to build C++ packages using CMake and integrate them with Pixi, including Python bindings with nanobind.
pixi-build is a preview feature and will change until stabilized. Keep this in mind when using it for your projects.

Why Build C++ with Pixi?

Pixi’s C++ build support enables:
  • Native performance with cross-platform builds
  • Python bindings using nanobind or pybind11
  • Mixed language projects combining C++ and Python
  • Conda ecosystem for C++ dependencies like SDL2, Boost, etc.

Creating a C++ Package with Python Bindings

Building C++ Applications

SDL2 Example

Here’s a complete example building an SDL2 application:
pixi.toml
Corresponding CMakeLists.txt:
CMakeLists.txt

Advanced Configuration

Custom CMake Arguments

Pass additional CMake configuration:

Specifying Compilers

The pixi-build-cmake backend automatically provides compilers. However, for special cases:
See dependency types for when to use build vs host dependencies.

Cross-Compilation Example

For cross-compilation from macOS ARM to Linux x86_64:

Using Git Sources

Build from a git repository:
pixi.toml
See package source configuration for more options.

Dependency Types for C++

Tools that run on your build machine:
For pixi-build-cmake, these are provided automatically.
Libraries and headers for the target platform:
These must match your target platform, not build platform.
Libraries needed at runtime:
Many conda packages have run-exports that automatically add run dependencies based on host dependencies.

Real-World Example: Mixed Project

Directory Structure

Root pixi.toml

pixi.toml

Using C++ from Python

src/python_rich/__init__.py
See the workspace guide for complete multi-package examples.

Next Steps

Workspaces

Combine C++ and Python packages

Dependency Types

Understand build, host, and run dependencies

Package Sources

Build from git or custom paths

Build Variants

Build for multiple Python versions

Troubleshooting

Ensure dependencies are in host-dependencies:
The conda environment sets CMAKE_PREFIX_PATH automatically.
Check the install path in CMakeLists.txt uses PYTHON_SITE_PACKAGES:
Verify platform settings:
  • Build platform: Your machine’s architecture
  • Host/target platform: Where the code will run