Compile C / C++ / Fortran source files using the compiler configured
by your R Makeconf file.
make(target = "all", makefile = r_makeconf_path())
make_call(cmd = "$(CC)", args = "--version")
make_echo(cmd = "$(CC)")
make_info()The make function literally calls make yourfile.o -f /path/to/R/Makeconf.
This is exactly what R does when building packages and hence the best
way to test if the compiler is working.
Other maketools:
diagnostics,
pkgconfig,
r_config,
sysdeps
# Test the CXX compiler
if(cxx_info()$available){
testprog <- '#include <iostream>\nint main() {std::cout << "Hello World!";}'
writeLines(testprog, con = 'testprog.cc')
make('testprog')
# Test and cleanup
system('./testprog')
unlink('testprog*', recursive = TRUE)
}
#> g++ -std=gnu++17 -g -O2 -I/usr/local/include -L/usr/local/lib testprog.cc -o testprog
# Run a program from a make variable
make_call('$(CXX)', '--version')
#> $status
#> [1] 0
#>
#> $stdout
#> [1] 67 2b 2b 20 28 55 62 75 6e 74 75 20 31 31 2e 34 2e 30 2d 31 75 62 75 6e 74
#> [26] 75 31 7e 32 32 2e 30 34 29 20 31 31 2e 34 2e 30 0a 43 6f 70 79 72 69 67 68
#> [51] 74 20 28 43 29 20 32 30 32 31 20 46 72 65 65 20 53 6f 66 74 77 61 72 65 20
#> [76] 46 6f 75 6e 64 61 74 69 6f 6e 2c 20 49 6e 63 2e 0a 54 68 69 73 20 69 73 20
#> [101] 66 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 73 65 65 20 74 68 65 20 73 6f
#> [126] 75 72 63 65 20 66 6f 72 20 63 6f 70 79 69 6e 67 20 63 6f 6e 64 69 74 69 6f
#> [151] 6e 73 2e 20 20 54 68 65 72 65 20 69 73 20 4e 4f 0a 77 61 72 72 61 6e 74 79
#> [176] 3b 20 6e 6f 74 20 65 76 65 6e 20 66 6f 72 20 4d 45 52 43 48 41 4e 54 41 42
#> [201] 49 4c 49 54 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20 50 41
#> [226] 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f 53 45 2e 0a 0a
#>
#> $stderr
#> raw(0)
#>
# Where your makeconf is stored:
make_info()
#> $name
#> [1] "make"
#>
#> $available
#> [1] TRUE
#>
#> $path
#> [1] "/usr/bin/make"
#>
#> $version
#> [1] "GNU Make 4.3"
#>
#> $makeconf
#> [1] "/opt/R/4.4.1/lib/R/etc/Makeconf"
#>