- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在努力让 Pybind 11 正常工作,但遇到了困难。我试着用这个编译我的 .cpp 文件:
c++ -Wall -std=c++11 -fPIC `python3 -m --includes` -I ~/Documents/Single_electron/pybind11/include single_e.cpp -o single_e `python-config --includes`
但是会出现一大堆错误,从这个列表开始:
single_e.cpp :(.text+0xaa): undefined reference to `Py_GetVersion'
single_e.cpp :(.text+0x104): undefined reference to `PyExc_ImportError'
single_e.cpp :(.text+0x123): undefined reference to `PyErr_Format'
single_e.cpp :(.text+0x1b2): undefined reference to `PyExc_ImportError'
single_e.cpp :(.text+0x1c0): undefined reference to `PyErr_SetString'
single_e.cpp :(.text+0x1f9): undefined reference to `PyExc_ImportError'
single_e.cpp :(.text+0x207): undefined reference to `PyErr_SetString'
有没有人对我应该如何解决这个问题有任何建议?
最佳答案
你拉 python 包括不止一种方式
python3 -m --includes
和
python-config --includes
第一个甚至不应该运行(你是说 python3-config --includes 吗?),无论如何,你需要决定你是想要 python2 还是 python3,并且只使用一个。
其次,您只处理了 python 的包含目录。您仍然需要告诉编译器如何链接库,这是您问题的核心。这是对 python-config 的另一个调用:python-config --ldflags
最后,您最好使用 --cflags 来获取包含目录,因为这还会设置一堆其他标志,以便您的编译代码符合 python 的约定。例如,这包括 -fPIC
。
所以,总结一下:
c++ -std=c++11 `python-config --cflags` -I ~/Documents/Single_electron/pybind11/include single_e.cpp -o single_e `python-config --ldflags`
当然,用正确的名称替换您的 python-config
,例如 python3-config
,如果那确实是您的目标。
关于c++ - Pybind11错误 undefined reference `Py_GetVersion',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52728091/
首先,感谢大家努力解决我的这个疑问。我正在转换一个最小的 C++ 项目以在 Python 中使用。这种努力背后的真正原因是为了速度。 我遇到了 PyBind,对它的功能以及他们提供的文档数量感到非常惊
我有以下类结构(我实际实现的简化示例): /* TestClass.hpp */ #pragma once template class CurRecTemplate { protected:
我有以下设置(1 个基类、1 个派生类、1 个容器)。容器采用 shared_ptr作为输入。 #include namespace py = pybind11; struct Base { };
我刚刚安装了 pybinding,我正在尝试运行该库文档中提出的第一个示例。 import pybinding as pb import numpy as np import matplotlib.p
我正在使用 pybind 包装一些 C++ 函数,然后在 Python 中使用它。我需要一些结构,但我不知道如何在 Python 中访问它的属性。我的结构没有只有方法的属性,所以我认为绑定(bind)
我使用以下命令创建了一个 miniconda 环境: conda create -n build_a_python_cpp_module xtensor-python -c conda-forge 激
为了更好地理解如何使用 pybind 库将参数从 Python 传递到 C++ 函数,我想构建一个小的虚拟/演示代码,我可以在其中接收 C++ 端的 Python 列表,将其转换为浮点指针对象,然后打
我正在尝试编译 Pybind11 C++ 中的模块它调用了几个头文件(.h)在上面。由于我有很多头文件,我决定做一个 Makefile ,没有问题,除了创建目标共享对象文件(s.o) .我需要这个共享
pybind 的新手 - 阅读文档,但我不了解如何将其应用于二维数组。 我有两个数组存储 3d 坐标 shape = (10,3) a = np.zeros(shape=(10,3)) b = np.
TL;博士 将 pybind11 绑定(bind)添加到工作中的 C++ DLL 项目允许我在 Python 中导入和使用生成的 DLL,但会破坏我使用 boost/dll 机制在 C++ 代码中使用
在 Pybind 中,可以通知 Python 关于函数的参数名称: m.def("add", &add, "A function which adds two numbers", py::arg(
当我运行 pip install .在我有 setup.py 的目录中。我正在使用 pybind11 为我的 C++ 项目构建一个 python 模块。 (同样,在 Windows 10 上) 我收到
我正在尝试使用 PyBind 在 C++ 中嵌入一些 Python 代码。大多数文档都是关于使用 C++ 扩展 Python,但我对嵌入感兴趣: 关于 http://pybind11.readthed
我正在尝试使用 pybind11 实现 C++ 到 python,并使用 pybind11-multiprocessing-hangs 。不同之处在于我想在c++中使用python对象并继续从c++调
我是一名优秀的程序员,十分优秀!