gpt4 book ai didi

c++ - 在MacOS上,简单pybind示例的编译失败

转载 作者:行者123 更新时间:2023-12-02 10:56:26 24 4
gpt4 key购买 nike

我正在尝试在pybind11文档中实现simple add function example。我正在使用默认的Mac python3(3.7.7),并通过pybind11安装了pip3 install pybind11
有一个example.cpp文件:

#include <pybind11/pybind11.h>


int add(int i, int j)
{
return i + j;
}

PYBIND11_MODULE(example, m)
{
m.doc() = "pybind11 example plugin"; //optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
我正在尝试使用 the default command they give for macos进行编译:
c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`
但是,这会导致一系列错误:
clang: error: unsupported option '--extension-suffix`'
clang: error: unknown argument: '-m'
clang: error: no such file or directory: '`python3'
clang: error: no such file or directory: 'pybind11'
我想念什么?我是否错过了设置 pybind11的步骤?

最佳答案

原来,我不得不单独将pybind11添加到我的路径中:

export PYTHONPATH=$PYTHONPATH:/usr/local/include/python3.7m/pybind11/

关于c++ - 在MacOS上,简单pybind示例的编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62521569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com