我目前正在嘗試在我的 Mac 上設(shè)置 Pybind。我遵循這些說(shuō)明:https://pybind11.readthedocs.io/en/stable/basics.html。我已經(jīng)在我的計(jì)算機(jī)上克隆了 pybind 存儲(chǔ)庫(kù),在該存儲(chǔ)庫(kù)中創(chuàng)建了構(gòu)建目錄,并運(yùn)行了測(cè)試用例 (make check -j 4)。這是我的目錄布局:Home/ ---example.cpp ---pybind11/我有一個(gè)我寫的 example.cpp 文件:#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我使用以下命令和標(biāo)志編譯它(來(lái)源: https: //pybind11.readthedocs.io/en/stable/compiling.html#building-manually):c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`我收到以下錯(cuò)誤:example.cpp:1:10: fatal error: 'pybind11/pybind11.h' file not found#include <pybind11/pybind11.h> ^~~~~~~~~~~~~~~~~~~~~1 error generated.當(dāng)我將文件移動(dòng)到 pybind11 存儲(chǔ)庫(kù)時(shí),我可以成功編譯,但執(zhí)行時(shí)會(huì)出現(xiàn)以下錯(cuò)誤:zsh: exec format error: ./example.cpython-37m-darwin.so任何幫助是極大的贊賞。跟進(jìn):我認(rèn)為 Seth 讓我更接近于讓它發(fā)揮作用(多謝),但我仍然遇到這個(gè)問(wèn)題: 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 executedIn 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 上遵循這些人的建議,但我得到了同樣的錯(cuò)誤: https: //github.com/pybind/pybind11/issues/1728#issuecomment-616619910
構(gòu)建 Pybind11 - 測(cè)試用例不會(huì)運(yùn)行?
當(dāng)年話下
2023-04-18 15:58:43