Skip to content

Tools

A lot goes into making a well structured C++ project, much more than any one team should have to do.

CMake

CMake is a powerfull build automation tool that makes compiling code for large projects with a lot of interoperating files a lot easier. Steps 1-3 of the official tutorial are great for understanding the basics.

GDB

The GNU Project Debugger is the most commonly debugger for the C language family. VSCode also has a degree of integration with GDB that allows an easy to use GUI. This GDB cheat sheet has all the GDB comands you will need to know. Be aware the VSCode has GUI buttons for some of these commands that are easier to use.

GoogleTest

GoogleTest is the C++ unit testing framework we will be using. The GoogleTest Primer is a good place to start.

Example
cached_fib.h
#include <vector>
class CachedFib {
public:
    void CachedFib(int n);
    int  getFib(int n);
private:
    std::vector<int> cache;
}
cached_fib.cpp
#include <iostream>
#include <vector>
#include "cached_fib.h"

void CachedFib::CachedFib(int n) {
    cache.push_back(0);
    cache.push_back(1);
    for (int i = 2; i < n; i++) {
        cache.push_back(cache[i - 1] + cache[i - 2]);
    }
}

int CachedFib::getFib(int n) {
    if (cache.size() < n) {
        for (int i = cache.size(); i < n; i++) {
            cache.push_back(cache[i-1] + cache[i-2]);
        }
    }
    std::cout << cache[n - 1] << std::endl;
}
test_cached_fib.cpp
#include "cached_fib.h"
#include "gtest/gtest.h"

CachedFib::testFib;

class TestFib : public ::testing::Test {
protected:
    void Setup override {
        // Every time a test is started, testFib is reinitialized with a constructor parameter of 5
        testFib = CachedFib(5);
    }
}

TEST_F(TestFib, TestBasic) {
    ASSERT_EQ(getFib(5), 3) << "5th fibonacci number must be 3!";
}

// more tests

Google Protocol Buffer

Google Protocol Buffer (Protobuf) is a portable data serialization method. We use it over other methods like JSON and XML because it produces smaller binaries, an important consideration when sending data across an ocean. Unfortunately, there does not seem to be a easy to follow tutorial for using them, but here are the C++ basics. The page is quite dense and can be hard to follow, so do not worry if you do not understand it.

Clang

In its most basic form, Clang is a compiler for the C language family. Clang has multiple benefits like easier portability compared to, for example, GCC. Clang is actually "half" the compiler, the other half being LLVM. Without going into unnecessary detail, Clang compiles C++ code to a generic language before LLVM compiles it to machine specific language.

Clangd

Clangd is the Clang language server. It provides a much more powerful intellisense than the default one used in VSCode's C/C++ extension.

Clang-Tidy

Clang-Tidy is a linting tool, who's main purpose is to catch potential programming errors caused by bad programming style/practices using just static analysis.

Clang Format

An autoformatting tool that makes enforcing style guidelines much easier. When se tup, it corrects formatting as soon as you hit save.

llvm-cov

We will use llvm-cov to evaluate our test coverage. When used with genhtml, we can generate HTML reports that that show our line, function, and branch coverage line-by-line.