【发布时间】:2020-04-22 14:17:49
【问题描述】:
我正在尝试找到一种方法来使用 pybind11 构建和运行带有嵌入式 python 解释器的 cpp 文件。
来自this tutorial,它使用 CMake,但我正在寻找一种不使用 CMake 的方法。
这是我尝试过的。
在example.cpp:
#include <pybind11/embed.h> // everything needed for embedding
namespace py = pybind11;
int main() {
py::scoped_interpreter guard{}; // start the interpreter and keep it alive
py::print("Hello, World!"); // use the Python API
}
当我运行以下命令时,在终端中:(构建良好)
c++ -O3 -Wall -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example
然后运行二进制文件
./example
我收到以下错误:
dyld:找不到符号:_PyBaseObject_Type 引用自: /Users/cuinjune/Desktop/pybindtest/./example 预期在:flat /Users/cuinjune/Desktop/pybindtest/./example zsh: abort 中的命名空间 ./例子
是否有任何可能的方法可以使用 pybind11 使用嵌入式 python 解释器正确构建和执行 cpp 文件? (不使用 CMake)
【问题讨论】: