首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构建Pybind11 -测试用例将不会运行?

构建Pybind11 -测试用例将不会运行?
EN

Stack Overflow用户
提问于 2020-08-01 16:38:40
回答 2查看 962关注 0票数 0

我目前正试图在我的Mac上设置Pybind。我遵循以下说明:https://pybind11.readthedocs.io/en/stable/basics.html

我在我的计算机上克隆了pybind,在该repo中创建了构建目录,并运行了测试用例(请检查-j 4)。

这是我的目录布局:

代码语言:javascript
复制
Home/
    ---example.cpp
    ---pybind11/

我编写了一个example.cpp文件:

代码语言:javascript
复制
#include <pybind11/pybind11.h>

namespace py = pybind11;

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

PYBIND11_MODULE(example, m) {
        m.doc() = "pybind11 example plugin";

        m.def("add", &add, "A function which adds two numbers");
}
example.cpp

我用以下命令和标志编译它(源代码:https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually):

代码语言:javascript
复制
c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`

我得到以下错误:

代码语言:javascript
复制
example.cpp:1:10: fatal error: 'pybind11/pybind11.h' file not found
#include <pybind11/pybind11.h>
         ^~~~~~~~~~~~~~~~~~~~~
1 error generated.

当我将文件移动到pybind11回购中时,我可以成功编译,但是执行会导致以下错误:

代码语言:javascript
复制
zsh: exec format error: ./example.cpython-37m-darwin.so

任何帮助都是非常感谢的。

跟进:我认为Seth让我更接近于让它发挥作用(谢谢),但我仍然有这样的问题:

代码语言:javascript
复制
    c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix` -I pybind11/include/ 
/Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named pybind11.__main__; 'pybind11' is a package and cannot be directly executed
In file included from example.cpp:1:
In file included from pybind11/include/pybind11/pybind11.h:44:
In file included from pybind11/include/pybind11/attr.h:13:
In file included from pybind11/include/pybind11/cast.h:13:
In file included from pybind11/include/pybind11/pytypes.h:12:
pybind11/include/pybind11/detail/common.h:122:10: fatal error: 'Python.h' file not found
#include <Python.h>
     ^~~~~~~~~~
1 error generated.

尝试在github上遵循这个家伙的建议,但我得到了同样的错误:https://github.com/pybind/pybind11/issues/1728#issuecomment-616619910

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-01 17:45:38

文件不在包含路径上。您可以将其安装到计算机中,默认包含路径,也可以将-I path_to_directory_containing_pybind11添加到编译命令中。

票数 0
EN

Stack Overflow用户

发布于 2020-08-03 15:53:40

问题解决: c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup PYTHONPATH=./pybind11 python -m pybind11 --includes example.cpp -o example3-config--扩展-后缀

使用makefile也有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63207598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档