C++ Support¶
autopxd2 supports C++ headers through the libclang backend.
Important
C++ support requires the libclang backend. The default pycparser backend only supports C99.
Basic C++ Usage¶
Or with Docker:
Supported C++ Features¶
Classes¶
C++ classes are converted to Cython structs:
Generates:
Structs¶
C++ structs work the same as C:
Functions¶
Global functions are converted directly:
Generates:
Namespaces¶
Currently, only top-level declarations are extracted. Namespaced declarations are not directly supported.
Limitations¶
Methods¶
Class methods are not included in the generated .pxd. Only public data members are extracted.
For full method support, you'll need to manually add method declarations or use Cython's cppclass syntax.
Templates¶
Template classes are supported through the libclang backend, including primary templates and full specializations. See C++ Template Support for details.
Overloading¶
Multiple overloaded functions with the same name may produce conflicts. You may need to manually select which overload to use.
Best Practices¶
- Use header-only libraries where possible for simpler integration
- Start with the Docker image to avoid libclang installation issues
- Check generated output and manually adjust for complex C++ features
- Consider Cython's cppclass for classes with methods you need to call
Example Workflow¶
-
Generate initial pxd:
-
Review and adjust for methods, templates, or other features
-
Create your Cython wrapper: