Skip to contents

C++ Setup

You will need a working C++ compiler capable of compiling C++11 code. To get it:

  • On Windows, install Rtools.
  • On Mac, install Xcode from the App Store.
  • On Linux, sudo pacman -Syu install build-essential g++-11 or similar.

For Ubuntu Users

After installing g++-11, you may still encounter issues compiling C++ code due to missing standard library headers. This does not happen when testing on Manjaro Linux.

You can try this:

sudo apt install build-essential g++-11 libc++-11-dev libc++abi-11-dev

Then you can attempt to compile a simple example to print a number:

// save this as 01-print-number.cpp or similar
#include <iostream> // required for the cout function

// function to print a message
int main() {
    std::cout << 1 << std::endl;
    return 0;
}

Then try to compile and run it with the following bash instruction:

g++ 01-print-number.cpp
./01-print-number # prints "1"

Otherwise, not installing the additional packages may lead to the following error:

fatal error: 'cstdio' file not found
fatal error: 'vector' file not found
cannot find -lc++abi: No such file or directory

R Setup

You can install the R packages bench, cpp4r, devtools and usethis with the following command:

install.packages(c("bench", "cpp4r", "devtools", "usethis"))

To verify that R can compile C++ code, you can run pkgbuild::check_build_tools(debug = TRUE), which will return an output similar to:

Trying to compile a simple C file
Running /usr/lib64/R/bin/R CMD SHLIB foo.c
using C compiler:gcc (GCC) 15.2.1 20250813