Compiles one or more C++ source files generated by cppODE(),
cvode() or cppFUN() into shared libraries (.so or .dll) using
R CMD SHLIB. The compile-time flags stored in an object's
"compileArgs" attribute apply to the source of that object only, also
when output links several sources into one library; flags passed
through args apply to every source. Every object is compiled anew, with
the makefiles of R CMD SHLIB, so a user Makevars (R_MAKEVARS_USER or
~/.R/Makevars) reaches the compile of each object as well as the link.
Arguments
- ...
One or more objects returned by
cppODE(),cvode()orcppFUN()that have a"srcfile"attribute.- output
Base name of one shared library for all objects, in the directory of the first source. Default
NULL: one library per object.- args
Optional additional compiler arguments, appended after the flags from
"compileArgs". DefaultNULL.- cores
Number of parallel compilation jobs: separate libraries, or the objects of a combined
output, are built side by side. Default1.- verbose
Logical; if
TRUE, show compiler commands. DefaultFALSE.
Note
The compiler package exports a function of the same name,
compiler::compile(); where both are attached, qualify the call.
Environment variables
CPPDE_EXTRA_CXXFLAGS is appended to the compiler flags of every
model compiled in the session, after "compileArgs" and args. Use
it to apply a define, an -march setting or a sanitizer to a whole
run without touching the call sites. Exporting PKG_CXXFLAGS has no
effect: compile() sets that variable itself.
CPPDE_EXTRA_LIBS is the linker counterpart, appended last to
PKG_LIBS. A sanitizer needs both: CPPDE_EXTRA_CXXFLAGS and
CPPDE_EXTRA_LIBS set to -fsanitize=thread builds and links the
generated models under ThreadSanitizer.
Examples
# \donttest{
if (codegenAvailable()) {
## Generate an ODE and an observable without compiling, then link both into
## one shared object next to their sources in tempdir().
f <- cppODE(c(x = "-k*x"), deriv = FALSE, compile = FALSE)
g <- cppFUN(c(y = "2*x"), variables = "x", compile = FALSE)
compile(f, g, output = "decay_and_double")
solveODE(f, times = 0:3, parms = c(x = 1, k = 1))$variable
g$func(x = 3)
}
#> using C++ compiler: g++ [-O2 -DNDEBUG -w -fPIC -fopenmp]
#> y
#> [1,] 6
# }