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…