Implementing a cross-platform native JIT has never been easier than today with LLVM. My GitHub project JitFromScratch shows how to use the LLVM ORC libraries to compile the code for a simple function at runtime:

template <size_t sizeOfArray>
int *integerDistances(const int (&x)[sizeOfArray], int *y) {
  int items = arrayElements(x);
  int *results = customIntAllocator(items);

  for (int i = 0; i < items; i++) {
    results[i] = abs(x[i] - y[i]);

  return results;

You can find out how to do this by following the history of the jit-basics branch. This article guides you through the steps to build the project on different platforms. Please note that the initial build process takes at least 1 hour and requires at least 15GB disk space.

Linux Mint 18

Mac OS X 10.12

Windows 10