如何在 pybind11 项目中设置包含路径
How to set the include path in a pybind11 project
我有一个大型C++库,我试图使用 pybind11 公开它。 我在正确设置包含路径时遇到问题。
项目目录的结构如下:
root
- sub-project-1
-> C++ files that know nothing about python.
- sub-project-2
-> more C++ files
-> sub-sub-project
-> even more C++ files
- sub-project-3
-> et cetera
- Interfaces
-> R
-> R interface stuff
-> python
-> package_name
-> setup.py
-> pybind11_bindings.cpp
setup.py 文件当前如下所示。 该结构主要从 pybind11 文档中复制而来。
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import sys
import setuptools
from glob import glob
__version__ = '0.0.1'
class get_pybind_include(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked. """
def __init__(self, user=False):
self.user = user
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
# omitting long lists of files.
my_sources = list_of_all_project_cpp_files + list_of_all_pybind11_binding_files
ext_modules = [
Extension(
'Boom',
sources=my_sources,
include_dirs=[
"../..",
# Path to pybind11 headers
get_pybind_include(),
get_pybind_include(user=True)
],
language='c++'
),
]
# some other stuff...
setup(
name='package_name',
version=__version__,
author='Me',
author_email='my.email@gmail.com',
url='https://a/url/to/somewhere',
description='description goes here.',
ext_modules=ext_modules,
install_requires=['pybind11>=2.3'],
setup_requires=['pybind11>=2.3'],
cmdclass={'build_ext': BuildExt},
zip_safe=False,
)
当我pip3安装./package_name时,我收到C++编译器错误,因为找不到库头。 我尝试将"include_dirs"参数更改为扩展以包含几个不同的 ../../..到达项目目录的顶部,但没有成功。
我宁愿不将完整的库复制到 .../python/project_name 目录中,除非这里的专家告诉我我需要这样做。
缺少的包含文件需要通过创建MANIFEST.in
文件包含在包中。
# This file lists all the header files to include with the distribution.
# See https://packaging.python.org/guides/using-manifest-in/ for syntax.
(commands using 'include' 'recursive-include' and 'graft' go here)
相关文章:
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- Cython 包含catkin_pkg设置的错误
- wxWidgets 自动会议设置未将包含目录设置为 -Isystem,而是设置为 -I
- 在C++中设置仅包含每个类的一个外观的数据结构
- 在Windows上设置CMake和vcpkg时出错"无法打开包含文件"
- 如何设置 CMake 来构建包含路径包含的代码,如 #include < libdir/lib>?
- 在Visual Studio Code(.json配置)中设置相对于工作区路径的c / c ++项目的包含路径
- 如何在 pybind11 项目中设置包含路径
- 通过程序代码行设置C++包含路径
- cout 打印的字符 [] 包含的字符数超过设置长度
- 在 ONE 设置中添加附加包含目录并引用 => 指向静态库
- 当对象包含其他对象的向量时,无法设置值
- 如何为所有 CLion 包含设置单个根
- 如何在 gtk 中设置包含宽字符的文本
- 如何在cmake中为每个项目设置包含目录
- Eclipse 找不到头文件管理器,即使已设置包含路径
- std::设置包含对与自定义比较器
- 在std::vector内部设置包含指针的boost::变量
- 我应该如何为我的程序设置包含布局
- 为什么必须链接库并设置包含目录