cpp11 icon indicating copy to clipboard operation
cpp11 copied to clipboard

How to include custom headers on top of generated cpp11.cpp?

Open vspinu opened this issue 4 years ago • 4 comments
trafficstars

My function returns external_pointer<MyClass>. How can I get a definition of MyClass into cpp11.cpp?

I was hoping for a declaration like [cpp11:include] which I can put in front of some statement and it will be automatically included in cpp11.cpp. Is there such a thing?

vspinu avatar Jul 30 '21 14:07 vspinu

Put the declarations in mypkgname_types.h and it will be included in the generated header.

jimhester avatar Jul 30 '21 14:07 jimhester

See also: https://cpp11.r-lib.org/articles/converting.html#type-aliases-1

bkietz avatar Jul 30 '21 14:07 bkietz

Great, thanks! Would be great if you could add a sentence to the docs of cpp_register about this. This is where people would search first for such info.

vspinu avatar Jul 30 '21 15:07 vspinu

Put the declarations in mypkgname_types.h

This doesn't seem to work for cpp11::cpp_source. I have tried all possible combinations <filename>_types.h, types.h, <filename>_types.hpp, and types.hpp.

vspinu avatar Nov 19 '21 22:11 vspinu