Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Advanced C++

You're reading from  Advanced C++

Product type Book
Published in Oct 2019
Publisher
ISBN-13 9781838821135
Pages 762 pages
Edition 1st Edition
Languages
Authors (5):
Gazihan Alankus Gazihan Alankus
Profile icon Gazihan Alankus
Olena Lizina Olena Lizina
Profile icon Olena Lizina
Rakesh Mane Rakesh Mane
Profile icon Rakesh Mane
Vivek Nagarajan Vivek Nagarajan
Profile icon Vivek Nagarajan
Brian Price Brian Price
Profile icon Brian Price
View More author details

Table of Contents (11) Chapters

About the Book 1. Anatomy of Portable C++ Software 2A. No Ducks Allowed – Types and Deduction 2B. No Ducks Allowed – Templates and Deduction 3. No Leaks Allowed - Exceptions and Resources 4. Separation of Concerns - Software Architecture, Functions, and Variadic Templates 5. The Philosophers' Dinner – Threads and Concurrency 6. Streams and I/O 7. Everybody Falls, It's How You Get Back Up – Testing and Debugging 8. Need for Speed – Performance and Optimization 1. Appendix

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

lock icon The rest of the chapter is locked
Next Chapter arrow right
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}