c++ - Windows/Cygwin - 无法使用 pybind11 - 出错
问题描述
我想在一个项目中集成实用工具 pybind11。我的工作环境是窗户。
要安装pybind11,有这个页面:Pybind First setps
我在 windows 和几天 (3) 下尝试了几次,使用 Eclipse,然后使用 Python 和 Mingw。然后使用 Visual Studio
经过这一切,我尝试了 Linux,并在 1 小时内来到了这个例子:
#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");
}
c++ -O3 -Wall -shared -std = c ++ 11 -fPIC示例.cpp
python3 -m pybind11 --includes
-o 示例python3-config --extension-suffix
用测试除了Python。
在此之后,我决定使用 cygwin 让它成功。
这是我的位置:
easy_install-3.6 pip
python3 -m pip install pytest
python3 -m pip install pybind11
python3 -m pip install python-config
然后在pybind11-master下
mkdir build
cd build
cmake ..
make check -j 4
我有两个警告和一个注释:
警告:“pybind11 :: buffer :: buffer (pybind11 :: handle, bool)”已弃用:使用 reinterpret_borrow () 或 reinterpret_steal () [-Wdeprecated-declarations]
链接时,这是一个错误,但有很多。
/tmp/ccqNl6ln.ltrans0.ltrans.o::(.text+0x12f16):未定义引用“pybind11 :: index_error :: index_error () [clone .lto_priv.4841] [clone .lto_priv.4883]”
pybind11 确实是该项目的一个加分项。但我不能在 Windows 上使用它。
有没有人用cygwin编译过pybind11?
非常感谢你
解决方案
使用 pip 安装 3 个模块后
python3 -m pip install pytest
python3 -m pip install pybind11
python3 -m pip install python-config
以下示例有效
#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");
}
如果编译为:
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix) -lpython3.6m
推荐阅读
- prolog - Prolog:模型简单多态类型
- mysql - 在 windows 10 services.msc 中看不到 MySQL
- git - 使用 GitHub Actions 从远程自动拉取
- c++ - 优化条件
- java - Android Studio 注册和登录应用程序 [JAVA / PHP]
- reactjs - 如何在 React.js 中使用道具禁用按钮?
- python - BigQuery:如何使用传输 API 将文件从 GCS 加载到现有表?
- java - Java - [Swing] 具有 2 个连接列的 Jlist
- yaml - knitr/Rmarkdown/pandoc : 如何在 .Rmd 文件中全局设置参考书目路径
- javascript - 有没有办法打印 history.go(-1) 的值