cpp11 icon indicating copy to clipboard operation
cpp11 copied to clipboard

How to set up `CPPFLAGS` with `cpp11::cpp_source`

Open vspinu opened this issue 2 years ago • 3 comments

Sorry if obvious, but I cannot figure out a way to provide compiler flags to cpp_soruce besides modifying the ~/.R/Makevars. A local Makevars file is not picked up.

vspinu avatar Oct 27 '21 14:10 vspinu

You should be able to set the environment variable R_MAKEVARS_USER to wherever you want it to be if you don't want to use the site wide makevars file. see https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Customizing-package-compilation

There isn't anything built into cpp11 to make this easier however.

jimhester avatar Oct 27 '21 14:10 jimhester

Thanks! I learned something new today.

Would it make sense for cpp11 to pick the Makevars in the working directory automatically? Similarly how the Makevars within packages works I would suggest.

vspinu avatar Oct 27 '21 22:10 vspinu

You can also temporarily set the PKG_CPPFLAGS environment variable (totally unverified hack on my end). For example, I use this to prototype C++ linking to my local development version of Arrow:

withr::with_envvar(
  list(
    PKG_CXXFLAGS = paste0("-I", Sys.getenv("ARROW_HOME"), "/include"),
    PKG_LIBS = paste0("-L", Sys.getenv("ARROW_HOME"), "/lib", " -larrow")
  ),
  cpp11::cpp_source("2021_11_05_copy_files.cpp")
)

paleolimbot avatar Nov 10 '21 14:11 paleolimbot