r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
199 stars 46 forks source link

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

Open vspinu opened 3 years ago

vspinu commented 3 years ago

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?

jimhester commented 3 years ago

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

bkietz commented 3 years ago

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

vspinu commented 3 years ago

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 commented 2 years ago

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.