mcpp index

compat.pybind11

#include

Seamless operability between C++11 and Python

#include <pybind11/embed.h>
mcpp add compat.pybind11@3.2.0-dev.6254086

用法

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

#include <pybind11/embed.h>
#include <python_sdk.h>

int main() {
    namespace py = pybind11;
    PyConfig config;
    PyConfig_InitPythonConfig(&config);
    const PyStatus status = PyConfig_SetBytesString(&config, &config.home, MCPP_PYTHON_HOME);
    if (PyStatus_Exception(status)) {
        PyConfig_Clear(&config);
        return 1;
    }
    py::scoped_interpreter interpreter(&config);
    PyConfig_Clear(&config);
    const int answer = py::eval("sum([1, 2, 3, 4])").cast<int>();
    py::dict globals;
    globals["double_value"] = py::cpp_function([](int value) { return 2 * value; });
    py::exec("result = double_value(21)", globals);
    return answer == 10 && globals["result"].cast<int>() == 42 ? 0 : 2;
}

tests/examples/pybind11/tests/embed.cpp · 项目 tests/examples/pybind11

构建

targets
pybind11 (lib)
language
c++23
C standard
c11
import std
no
include dirs
*/include

源文件 (1)

  • mcpp_generated/pybind11_anchor.c

生成的文件

  • mcpp_generated/pybind11_anchor.c

版本

版本平台 镜像sha256
3.2.0-dev.6254086 最新 LinuxWindowsmacOS 源站 4a77778750ae…