[QUESTION] Pybind11 undefined classes. Can't bind to object with definition unavailable at compile time.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Hello,
I'm having issues where my classes are undefined. I figured this is a pretty basic use case, but I couldn't find anything relevant when I searched for a solution. So I could use some help. Anyways, my PYBIND11_MODULE looks like this:
py::class_<PDPage>(m, "PDPage");
py::class_<APDFLDoc>(m, "APDFLDoc")
.def(py::init<const char*, bool>())
.def("getPage", &APDFLDoc::getPage);
I have this class called APDFLDoc and I want to create a binding for one of its methods, getPage. But when I try to build it in VS, I get this error message:
Error C2139 '_t_PDPage': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_base_of' RenderPage C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\include\type_traits 1185
Now I think I know why this is happening. getPage is trying to create an object, a PDPage, from a class/struct that has no definition at compile-time because it is coming from a .dll. I raised the same question on Gitter, and I was told that Pybind11 has no support for this out of the box. I am wondering if you have a better solution than the one proposed there, which seems highly risky and time consuming. When I started using Pybind11, I assumed this was a basic use case and am surprised to have found no clear answer.
I also have a gist here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PYBIND11_MODULE snippet, the linked gist, and the Visual Studio C2139 diagnostic in the issue. Reproduce the reported binding scenario and determine whether the undefined PDPage type is supported; done requires a confirmed solution or a clear statement of the supported approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100