gpt4 book ai didi

c++ - Windows/Cygwin - 无法使用 pybind11 - 出错

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

我想在一个项目中集成实用工具 pybind11。
我的工作环境是 window 。

要安装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 python3 -m pybind11 --includes example.cpp -o examplepython3-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

我有两个警告和一个注释:

warning: "pybind11 :: buffer :: buffer (pybind11 :: handle, bool)" is deprecated: Use reinterpret_borrow () or reinterpret_steal () [-Wdeprecated-declarations]



链接时,这是一个错误,但有很多。

/tmp/ccqNl6ln.ltrans0.ltrans.o::(.text+0x12f16): undefined reference to "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

关于c++ - Windows/Cygwin - 无法使用 pybind11 - 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53115907/

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