compat.nanobind
#includeSeamless 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.hppmcpp_generated/nanobind_anchor.c