亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

構建 Pybind11 - 測試用例不會運行?

構建 Pybind11 - 測試用例不會運行?

當年話下 2023-04-18 15:58:43
我目前正在嘗試在我的 Mac 上設置 Pybind。我遵循這些說明:https://pybind11.readthedocs.io/en/stable/basics.html。我已經在我的計算機上克隆了 pybind 存儲庫,在該存儲庫中創建了構建目錄,并運行了測試用例 (make check -j 4)。這是我的目錄布局:Home/    ---example.cpp    ---pybind11/我有一個我寫的 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我使用以下命令和標志編譯它(來源: 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`我收到以下錯誤:example.cpp:1:10: fatal error: 'pybind11/pybind11.h' file not found#include <pybind11/pybind11.h>         ^~~~~~~~~~~~~~~~~~~~~1 error generated.當我將文件移動到 pybind11 存儲庫時,我可以成功編譯,但執行時會出現以下錯誤:zsh: exec format error: ./example.cpython-37m-darwin.so任何幫助是極大的贊賞。跟進:我認為 Seth 讓我更接近于讓它發揮作用(多謝),但我仍然遇到這個問題:    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 上遵循這些人的建議,但我得到了同樣的錯誤: https: //github.com/pybind/pybind11/issues/1728#issuecomment-616619910
查看完整描述

2 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

文件 <pybind11/pybind11.h> 不在您的包含路徑中。您可以將它安裝到您機器的默認包含路徑中,或者將 -I path_to_directory_containing_pybind11 添加到您的編譯命令中。



查看完整回答
1 反對 回復 2023-04-18
?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

問題解決:c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup PYTHONPATH=./pybind11 python -m pybind11 --includesexample.cpp -o example`python3-config --extension-suffix

使用 makefile 也可以。


查看完整回答
反對 回復 2023-04-18
  • 2 回答
  • 0 關注
  • 455 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號