Installation and Setup
Before you embark on this book, you will need to install the following libraries used in this book. You will find the steps to install these here.
Installing CMake
We will use CMake version 3.12.1 or later. We have two options for installation.
Option 1:
If you are using Ubuntu 18.10, you can install CMake globally using the following command:
sudo apt install cmake
When you run the following command:
cmake –version
You should see the following output:
cmake version 3.12.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
If the version you see here is lower than 3.12.1 (for example, 3.10), you should install CMake locally using the following instructions.
Option 2:
If you are using an older Linux version, you may get a CMake version that is lower than 3.12.1. Then, you need to install it locally. Use the following commands:
wget \
https://github.com/Kitware/CMake/releases/download/v3.15.1/cmake-3.15.1-Linux-x86_64.sh
sh cmake-3.15.1-Linux-x86_64.sh
When you see the software license, type y and press Enter. When asked about the installation location, type y and press Enter again. This should install it to a new folder in your system.
Now, we will add that folder to our path. Type the following. Note that the first line is a bit too long and the line breaks in this document. You should write it as a single line, as follows:
echo "export PATH=\"$HOME/cmake-3.15.1-Linux-x86_64/bin:$PATH\"" >> .bash_profile
source .profile
Now, when you type the following:
cmake –version
You should see the following output:
cmake version 3.15.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
3.15.1 is the current latest release at the time of writing this document. Since it is newer than 3.12.1, this will suffice for our purposes.
Installing Git
Test the current installation by typing the following:
git --version
You should see a line such as the following:
git version 2.17.1
If you see the following line instead, you need to install git:
command 'git' not found
Here is how you can install git in Ubuntu:
sudo apt install git
Installing g++
Test the current installation by typing the following:
g++ --version
You should see an output such as the following:
g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If it is not installed, type the following code to install it:
sudo apt install g++
Installing Ninja
Test the current installation by typing the following:
ninja --version
You should see an output such as the following:
1.8.2
If it is not installed, type the following code to install it:
sudo apt install ninja-build
Installing Eclipse CDT and cmake4eclipse
There are multiple ways of installing Eclipse CDT. To get the latest stable version, we will use the official installer. Go to this website and download the Linux installer: https://www.eclipse.org/downloads/packages/installer.
Follow the instructions there and install Eclipse IDE for C/C++ Developers. Once you have installed it, run the Eclipse executable. If you did not change the default configuration, typing the following command in the terminal will run it:
~/eclipse/cpp-2019-03/eclipse/eclipse
You will choose a workspace folder and then you will be greeted with a Welcome tab in the main Eclipse window.
Now, we will install cmake4eclipse. An easy way to do this is to go to this website and drag the Install icon to the Eclipse window: https://github.com/15knots/cmake4eclipse#installation. It will ask you to restart Eclipse, after which you are ready to modify the CMake project to work with Eclipse.
Installing GoogleTest
We will install GoogleTest in our system, which will also install other packages that are dependent on it. Write the following command:
sudo apt install libgtest-dev google-mock
This command installs the include files and source files for GoogleTest. Now, we need to build the source files that we installed to create the GoogleTest library. Run the following commands to do this:
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
sudo cp *.a /usr/lib