Getting ready

Our code example consists of three files. The implementation source file, sum_integers.cpp, does the work of summing up over a vector of integers, and returns the sum:

#include "sum_integers.hpp"  #include <vector>int sum_integers(const std::vector<int> integers) {  auto sum = 0;  for (auto i : integers) {    sum += i;  }  return sum;}

For this example, it does not matter whether this is the most elegant implementation of a sum over a vector. The interface is exported to our example library in sum_integers.hpp, as follows:

#pragma once  #include <vector>int sum_integers(const std::vector<int> integers);

Finally, the main function is defined in main.cpp, which collects the command-line arguments from argv[], converts them into a vector ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.