mcpp index

compat.nanobind

#include

Seamless operability between C++17 and Python (runtime source embedded by the consumer)

#include <nanobind/nanobind.h>
mcpp add compat.nanobind@3.1.0

用法

来自本仓库自己的测试项目 —— CI 真的编译并运行过,不是为了网站写的。

// compat.nanobind — expose a module to an embedded interpreter, then let Python
// exercise every advertised surface: a free function with named arguments, STL
// conversion, a class with a read-only property, and exception translation.
//
// The nanobind runtime (src/nb_combined.cpp) is compiled in src/nb_runtime.cpp,
// not here: NB_MODULE needs the headers only, exactly as a real extension does.
#include <nanobind/nanobind.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/vector.h>

#include <python_sdk.h>

#include <cstdio>
#include <stdexcept>
#include <string>
#include <vector>

namespace nb = nanobind;

namespace {

int add(int a, int b) { return a + b; }
// …

tests/examples/nanobind/tests/embed_module.cpp · 项目 tests/examples/nanobind

构建

targets
nanobind (lib)
language
c++23
C standard
c11
import std
no
include dirs
include, mcpp_generated/include

源文件 (1)

  • mcpp_generated/nanobind_anchor.c

生成的文件

  • mcpp_generated/include/mcpp_nanobind_combined.hpp
  • mcpp_generated/nanobind_anchor.c

版本

版本平台 镜像sha256
3.1.0 最新 LinuxWindowsmacOS CN GLOBAL 39659890a112…