如何用“ pybind11”在两个不同的子模型中导出相同的类型?
在我的C ++库中,我有两个共享符号的名称空间:
namespace NS1 {
struct S1 { };
}
namespace NS2 {
using NS1::S1;
struct S2 { };
}
我想用相同的结构导出我的python模块的两个子模块, ie 具有subpodule ns1
export ie export 代码> s1 ,ns2
导出s1
和s2
,带有s1
是相同的类型在两个模块中。
我尝试过这样的方法:
PYBIND11_MODULE(my_module, m) {
py::module_ m1 = m.def_submodule("NS1", "");
py::module_ m2 = m.def_submodule("NS2", "");
py::class_<NS1::S1>(m1, "S1");
py::class_<NS2::S1>(m2, "S1");
py::class_<NS2::S2>(m2, "S2");
}
但这不起作用:
Traceback (most recent call last):
File "/test-python.py", line 3, in <module>
from my_module import *
ImportError: generic_type: type "S1" is already registered!
如何从两个不同的子模型中导出相同的类型?
In my C++ library I have two namespaces that share some symbol:
namespace NS1 {
struct S1 { };
}
namespace NS2 {
using NS1::S1;
struct S2 { };
}
I would like to export two submodule of my Python module with the same structure, i.e. having the submodule NS1
export S1
, and NS2
export both S1
and S2
, with S1
being the same type in both modules.
I tried this way:
PYBIND11_MODULE(my_module, m) {
py::module_ m1 = m.def_submodule("NS1", "");
py::module_ m2 = m.def_submodule("NS2", "");
py::class_<NS1::S1>(m1, "S1");
py::class_<NS2::S1>(m2, "S1");
py::class_<NS2::S2>(m2, "S2");
}
But this does not work:
Traceback (most recent call last):
File "/test-python.py", line 3, in <module>
from my_module import *
ImportError: generic_type: type "S1" is already registered!
How can I export the same type from two different submodules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论