[R-pkg-devel] C++ library USING_R
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Thu Oct 15 03:40:45 CEST 2020
On 14 October 2020 at 15:56, Joseph Park wrote:
| Dear R-devel,
|
| The Writing R Extensions manual states:
|
| 6.14 Platform and version information
| The header files define USING_R, which can be used to test if the code
| is indeed being used with R.
|
| I suppose this only applies to building R itself? Or, perhaps when Rcpp
| is used for the interface, or if one includes R headers explicitly.
|
| I have a C++ library that is built with no R-dependencies, then wrapped
| with an Rcpp interface. This same library is wrapped with pybind11 in
| the Python world, and directly used in C++ applications.
|
| How can the C++ library code "know" that it's R building the library? Is
| there a platform-independent environment variable or macro?
So if I have this right you have
- a library LIB using only standard C++ components
- that you wrapped into a Python package via pybind11, and
- that you want to build for R and 'let it know it used for R'
Well I think you would then use a (wrapper) R package R_LIB and could set up
a -DR_BUILD in the src/Makevars for R_LIB. This presume that you actually
recompile LIB as part of the build; if you were to link with a static or
shared build then you could not do this _for lack of a subsequent
compilation_ and can only rely on run-time information.
Hope this helps, and that I didn't misunderstand the question.
Dirk
--
https://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
More information about the R-package-devel
mailing list