Updating pybind and ImportError: dynamic module
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 领域
- backend, build-system
调研方向
从 src/python/libb.cpp 和 issue 中展示的 CMake 配置开始,然后使用 pybind11 2.6.0 和 2.7.1 或更高版本在 Python 3.9 中复现这些导入。比较两个构建时,检查构建出的扩展及其导出的模块入口点。升级后,如果 liba 和 libb 都能成功导入,并且相关构建配置已记录或修正,则视为完成。
由索引模型根据 Issue 内容生成。
描述
my code uses a very old version of pybind: 2.6.0 and everything works fine.
I have two modules, liba and libb
With 2.6.0 I have:
>>> import liba
>>> import libb
>>>
Same code on 2.7.1 and higher, and I get the following error.
I didn't change one single line in the code.
Importing liba still works, but libb fails.
>>> import liba
>>> import libb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_libb)
My module is correctly defined in a cpp file.
PYBIND11_MODULE(libb, m)
My CMake looks like this:
if (BUILD_SHARED_LIBRARY)
set(TARGET_LINK_LIBS liba-shared Eigen3::Eigen)
target_link_libraries(objlib PUBLIC ${TARGET_LINK_LIBS})
find_package(Python REQUIRED COMPONENTS Interpreter Development)
include_directories("${Python_INCLUDE_DIRS}")
add_library(objlib-py OBJECT src/python/libb.cpp)
SET(TARGET_LINK_LIBS_PY Python::Module pybind11::pybind11 ${TARGET_LINK_LIBS})
target_include_directories(objlib-py PUBLIC ${TARGET_INCLUDE_DIRS})
target_link_libraries(objlib-py PUBLIC ${TARGET_LINK_LIBS_PY})
set_property(TARGET objlib-py PROPERTY POSITION_INDEPENDENT_CODE ON)
set(SHARED_LIB ${CMAKE_PROJECT_NAME})
add_library(${SHARED_LIB} SHARED $<TARGET_OBJECTS:objlib> $<TARGET_OBJECTS:objlib-py>)
target_compile_definitions(${SHARED_LIB} PRIVATE VERSION_INFO=${PROJECT_VERSION})
target_include_directories(${SHARED_LIB} PUBLIC ${TARGET_INCLUDE_DIRS})
target_link_libraries(${SHARED_LIB} PUBLIC ${TARGET_LINK_LIBS_PY})
list(APPEND RISK_TARGETS ${SHARED_LIB})
endif (BUILD_SHARED_LIBRARY)
And my environment:
$ python3 --version
Python 3.9.2
$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
I compile my libs with gcc12
I am puzzled why upgrading the version of pybind makes my imports fail. Maybe I am doing something wrong, but I can't pinpoint it.
- 主要语言
- C++
- 星标
- 671
- 派生
- 220
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pybind/cuda_example 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
pybind/cuda_example#191 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
pybind/cuda_example#187 · 8 条评论 ·
-
难度 4/5 3-5 天 新手友好度 38/100
pybind/cuda_example#132 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
pybind/cuda_example#123 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 25/100
pybind/cuda_example#122 · 5 条评论 ·
查看 pybind/cuda_example 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
-
triage
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
patrick-hudson/put.gd-desktop#2044 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
uxlfoundation/oneDNN#6604 · 1 条评论 ·
维护者通常 2 天内回复