Tips & recipes
Use
examples/shapesorexamples/cellsas a starting point.Incremental rewrites. By default cppwg only rewrites wrapper files whose content has changed, leaving unchanged files untouched so build systems skip recompiling them. Pass
--overwriteto force a full rewrite of all wrapper files.One file per templated class. A templated class’s instantiations share a single wrapper file:
Foo<2>andFoo<3>are wrapped in oneFoo.cppwg.hpp/Foo.cppwg.cpppair (declaring and defining aregister_Foo_2_classandregister_Foo_3_classeach) rather than a separate file pair per instantiation. This reduces the number of generated files and the translation units the build has to compile.CastXML flags. To pass extra flags to the castxml clang frontend (e.g. to silence a diagnostic), use
--castxml_cflags. Values starting with-must use=, e.g.--castxml_cflags="-Wno-deprecated".Consistent smart-pointer holders. pybind11 requires the same holder type across a class hierarchy. Set
smart_ptr_typeonce at the package level rather than per class, so a base and its derived classes cannot end up with mismatched holders (which fails to compile).Unresolved / linker errors after generation usually mean a wrapped signature references a type whose instantiation was never produced. See uninstantiated-dependency dropping — cppwg drops such instantiations and logs why; instantiate the dependency to keep the class.
See the pybind11 documentation for help writing and understanding the generated wrapper code.