PDF Beginning C++ Compilers: An Introductory Guide to Microsoft C/C++ and MinGW Compilers 1st Edition Berik I. Tuleuov download
PDF Beginning C++ Compilers: An Introductory Guide to Microsoft C/C++ and MinGW Compilers 1st Edition Berik I. Tuleuov download
com
https://ebookmass.com/product/beginning-c-compilers-an-
introductory-guide-to-microsoft-c-c-and-mingw-compilers-1st-
edition-berik-i-tuleuov/
OR CLICK HERE
DOWLOAD NOW
https://ebookmass.com/product/beginning-c-compilers-an-introductory-
guide-to-microsoft-c-c-and-mingw-compilers-1st-edition-tuleuov/
ebookmass.com
https://ebookmass.com/product/critics-compilers-and-commentators-an-
introduction-to-roman-philology-200-bce-800-ce-james-zetzel/
ebookmass.com
https://ebookmass.com/product/beginning-c-from-beginner-to-pro-7th-
edition-gonzalez-morris/
ebookmass.com
https://ebookmass.com/product/theatre-in-your-life-3rd-edition-ebook-
pdf/
ebookmass.com
https://ebookmass.com/product/etextbook-pdf-for-food-around-the-world-
a-cultural-perspective-4th-edition/
ebookmass.com
https://ebookmass.com/product/the-first-order-the-chronicles-of-
sister-june-book-1-amy-cross/
ebookmass.com
https://ebookmass.com/product/artistic-and-cultural-dialogues-in-the-
late-medieval-mediterranean-1st-ed-edition-maria-marcos-cobaleda/
ebookmass.com
Introduction to law 7th Edition Edition University Of
South Alabama
https://ebookmass.com/product/introduction-to-law-7th-edition-edition-
university-of-south-alabama/
ebookmass.com
Beginning C++ Compilers
Berik I. Tuleuov • Ademi B. Ospanova
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and
the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM
Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint, paper-
back, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk
Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on the Github repository: https://github.com/Apress/Beginning-CPP-Compilers. For more
detailed information, please visit https://www.apress.com/gp/services/source-code.
vii
viii Contents
8 Minimal Systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.1 MSYS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
8.2 Default Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.3 Easy Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.4 Some Tips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.5 MSYS2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.6 Default Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.7 Easy Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.8 CMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.9 Default Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.10 Easy Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
8.11 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9 Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
9.1 GCC/MinGW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
9.1.1 Default Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.1.2 Building from the Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.1.3 Easy Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.2 Microsoft C/C++ Optimizing Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
9.2.1 Default Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
9.2.2 Easy Installation (Without Visual Studio)
with EWDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
9.2.3 Using Microsoft C/C++ Compiler with EWDK . . . . . . . . . . 101
9.2.4 Microsoft C/C++ Compiler Options . . . . . . . . . . . . . . . . . . . . . . . 102
9.2.5 Using MSBuild with EWDK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.3 Intel C/C++ Optimizing Compiler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
10.1 Dynamic and Static Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
10.2 Building Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
10.3 Creating User Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
10.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
11 Using Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.1 Linking with Static Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
11.2 Linking with Dynamic Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
11.3 Using Libraries from Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
11.4 Universal CRT Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
11.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
12 GMP (GNU Multiprecision Library) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
12.1 Building . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
12.1.1 GNU MPFR Library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
12.2 Example: Computation of 10 000 000!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
12.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
x Contents
13 Crypto++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
13.1 Building with MinGW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
13.2 Building with Microsoft C/C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 152
13.3 Example: AES Implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
13.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
14 OpenSSL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
14.1 Building with MinGW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
14.2 Building with Microsoft C/C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 159
14.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
15 Process Hacker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
15.1 Building with Microsoft C/C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . 167
15.1.1 Building Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
15.1.2 Building Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
15.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
A Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
About the Authors
xi
About the Technical Reviewer
xiii
Acknowledgments
Ademi would like to dedicate the book to her fragile but strong mother who cares
for her entire family. She provides Ademi with warmth and the opportunity to do
her job.
xv
Introduction
Anyone who wants to start programming in the C/C++ languages needs two things
in general: a computer and two programs called a C/C++ language compiler and a
source code editor (generally speaking, the so-called debugger — a program that
helps find errors in the source code, but still it is not necessary). More, in principle,
nothing is needed.
If any text editor (for example, Notepad on Windows) is in principle suitable as
a source code editor, then the situation with compilers is not simple. On Windows,
they must be installed, and in the vast majority of cases, when it comes to installing
the C/C++ compiler, for some reason it means installing Microsoft Visual Studio,
which requires a lot of computer resources. Meanwhile, Microsoft Visual Studio is
not a compiler, but the so-called Integrated Development Environment (IDE), which
includes, among other components, also a C/C++ language compiler.
As far as we know, there are no books devoted to installing C/C++ compilers1 ,
it is implicitly assumed that the user has the compiler either already installed, or
its installation is standard and does not cause difficulties. However, there are many
pitfalls here, and we will try to briefly describe the motives that prompted us to write
our book.
Under Windows, usually installing a C/C++ compilers, especially Microsoft
ones, takes quite a lot of time, because it comes with Microsoft Visual Studio for
the vast majority of users. Installing Visual Studio requires usually about 40 GB of
disk space and big amount of RAM, so it is impossible to use weak hardware. So
we suggest an easy way to deploy Microsoft C/C++ compiler: no headache with
disk space and hardware resources lack. Additionally, our means saves big amount
of time since one can deploy software on removable devices, such as flash sticks,
and use it easily in a portable way. We achieve this by using Enterprise Windows
Driver Kit (EWDK), a single, large ISO file, which can be mounted as virtual
device and used directly without any installation. EWDK contains everything from
Visual Studio except IDE. EWDK also allows to use MASM64 (Microsoft Macro-
Assembly) and C# compilers. With the aid of MSBuild System one can compile
Visual Studio Projects (.vcxproj) and Solutions (.sln) even without Visual Studio!
Analogously, MinGW compilers can be deployed from 7z/zip archives, simply by
xvii
xviii Introduction
unpacking into appropriate location. Briefly, both Microsoft C/C++ and MinGW
compilers can be used as portable software. Notice that such approach does not
require an administrative privileges at all.
It is Create Once, Use Many principle: one can deploy these compilers and
auxiliary software on removable device and use everywhere, or just copy it to hard
disk and use them from local disk. There is no need to re-install.
Also, users can use several versions of these compilers at the same time, they do
not interfere each other. Using MSYS (Minimal SYStem, a port of GNU Autotools)
allows to build under Windows many libraries originally designed for Unix-systems.
These things important because standard installation procedure doesn’t give such a
flexibility: very often various versions of installed software conflict with each other,
or it is impossible to install at all.
Our book is intended primarily for two categories of users:
• beginners to learn the C/C++ language, who don’t want to spend time on the
standard installation of MinGW and Microsoft C/C++ compilers, since in the
first case one has to make a difficult and non-obvious choice between different
builds of this compiler, and in the second — to solve computer resources lack
and installation problems;
• advanced users who, generally speaking, are not professional programmers, but
write small programs in standard C/C++, for, for example, scientific and technical
calculations.
Of course, the approach we propose can also be useful for professional program-
mers, as it saves a lot of time; in addition, the created toolkit can be used in the
future on a variety of computers without special preparation, since this toolkit is
portable.
We describe the MinGW and Microsoft C/C++ compilers, the clang compiler
is not covered (its popularity has not yet reached the level of first two). We set
as our main goal the description of compilers, and not various IDEs, so they are
practically not considered. Various advanced (lightweight) editors that have some
IDE functions are considered as code editors. We do not consider the currently
popular Visual Studio Code due to the fact that it is not lightweight (as we have
already noted, the IDE is an auxiliary tool for us; however, if the user has enough
memory installed on the computer, then nothing prevents using VS Code). We do not
consider code debuggers, an interested reader can later deal with this topic himself.
Also, we do not consider WSL (Windows Subsystem for Linux), since this
subsystem is designed to run Linux applications (and not all of them: for example,
restrictions apply to GUI applications) under Windows, and we are fighting to
build Open Source applications and libraries originally created for Unix systems
for Windows. WSL, although it provides less resource consumption compared to
virtualization, is still an additional layer that negatively affects the performance of
applications running under it. The programs and libraries compiled under Windows
using the tools we describe are native Windows applications and thus provide the
highest performance.
Introduction xix
General information on files and devices is given in this chapter. The concept of a
file is fundamental to computer science, so it’s important to be clear about it. The
issues of effective user interaction with the computer are also discussed.
not mandatory: for example, text editors can open the text file named “Readme”;
however, some software require strong extensions for their files.
Most file formats are designed to be independent of processor platforms and
operating systems. This means, for example, that the same pdf document can be
opened on Windows, Linux, Mac OS, Android devices, and finally iOS. However,
this is not the case for binary executables, which we will discuss as follows.
Before moving on, we need to make some clarifications. Most computer users, are
dealing with a modern and convenient graphical shell that provides ease of work.
The graphical shell of Windows is Explorer. The shell is an intermediary between
the user and the operating system, allowing you to open files, run programs, etc. In
the graphical shell, the mouse plays an important role, with which you can click the
icons of programs and documents to launch and open them.
However, the graphical shell is not the only one—there is another one, which is
called the command line. In the command line, the main role is played by another
device—the keyboard. The command line is mainly used to run commands by
typing the name of the command in the prompt and pressing the key. The
command can be either a system command (e.g., set or echo) or an executable
program file, and you must specify the exact location (full path to this file) of this
file. If such a file is not found due to nonexistence or an incorrect full path to it, the
system will display a corresponding message:
E:\Test>mycommand
'mycommand' is not recognized as an internal or external command,
operable program or batch file.
E:\Test>
Commands can have parameters called options. Their number depends on the
purpose of the command. As a rule, commands have built-in help, which in
Windows is called like this:
E:\Test>echo /?
Displays messages, or turns command-echoing on or off.
E:\Test>
So how to find this command line? Very simple: Press the + keys
and type cmd (cmd.exe is also possible) and press the key. Windows
will bring up a command prompt window.
Windows '.exe' files have so-called “magic bytes”: their first two bytes are
always 'MZ'.
Batch files on Windows have extensions '.bat' and '.cmd'.
Executable files in '.exe' and '.com' formats as well as batch files
('.bat', '.cmd') can be directly launched by the user. This can be done both
in the graphical shell and on the command line. In the graphical shell, open the
Explorer window, find the file to be launched, and double-click it. For the second
method, launch the command prompt, type the full file name, and press the
key.
Notice that for binary executable files and batch files, when they are executed,
their extensions can be omitted on the command line. In this regard, an inter-
esting question arises: If the files test.bat, test.cmd, test.com, and
test.exe are in the same directory, then which one will be executed when the
test command is executed?
Answer: The order of execution is '.com', '.exe', '.bat', '.cmd';
hence, test.com will be executed. To execute any other of them, you need to
write its name in full with the extension, for example, test.exe. In general, the
execution priority is determined by the PATHEXT environment variable and can be
changed, which we will talk about later.
A batch file is a text file, each line of which consists of a single command that
can have parameters. Thus, a batch file can execute several commands sequentially
one after another, that is, by running one command, we actually execute a whole
series of commands! Therefore, such files are sometimes called script files.
It is important to note that binary executables are not only operating sys-
tem dependent but also processor architecture dependent: for example, Windows
'.exe' files do not run on Linux or Mac OS; moreover, '.exe' files created
for 64-bit Windows do not work in 32-bit Windows (the opposite is true: 32-bit
Windows '.exe' files work in 64-bit Windows in compatibility mode). Likewise,
Linux binaries don’t work on Windows.
Batch files are a bit more flexible in this regard: while Windows '.bat' and
'.cmd' files don’t work on Linux, you can create script files on Windows that are
cross-platform with some limitations. We will cover this in later chapters.
Note In Unix systems, every file can be made executable in terms of those systems.
1.4 Mounting Devices 5
System commands are for executing common basic system commands. System
commands are divided into internal and external ones. Internal commands are
implemented in the CMD.EXE file; external commands are implemented as
separate utilities located in the C:\WINDOWS\System32 system directory. An
example of an external command is the abovementioned xcopy (xcopy.exe),
an advanced file and directory copying utility.
Help on these commands, as noted earlier, can be called with the /?.
We briefly describe here some useful commands:
Sometimes, in Windows you have to change the letter of the CD/DVD drive or even
the hard disk partition. This can be done through the Computer Management applet,
which is invoked by right-clicking the Computer icon in the Desktop. Note
that this requires administrator rights.
Much more interesting and useful is the subst command, which does not
require administrator rights and allows you to mount a folder as a disk partition,
assigning a given letter to this disk:
E:\Test>subst /?
Associates a path with a drive letter.
E:\Test>
6 1 Files and Devices
will create disk X: in the system (if it, of course, did not exist) and mount all the
contents of the E:\Test directory on this disk. We will use this command later
when working with the Microsoft C/C++ compiler.
Some software is shipped in the ISO format. Examples are Linux distributions,
Microsoft Enterprise Windows Driver Kit, and others. As we know, the ISO file
is an image of CD/DVD media, and in the old days, the user had to burn this file to
a blank CD/DVD disk and insert the disk into the drive. In our days, it is much more
easier to handle such files— it suffices to use the so-called virtual devices. The user
just creates such a device and mounts the ISO file on the device.
We work with DVD virtual devices. Virtual devices are created programmati-
cally; no physical device is needed. Such devices can easily be created on Windows
7 with the aid of several software: DAEMON Tools Lite (www.daemon-tools.
cc/products/dtLite), Alcohol 120% Free Edition (http://trial.alcohol-soft.com/en/
downloadtrial.php, all Windows operating systems except 98/ME, for personal use
only), etc. These tools require installation and system reboot.
In our opinion, the best program of this kind is WinCDEmu, an open source
CD/DVD/BD emulator (https://wincdemu.sysprogs.org); this program has a
portable version (https://wincdemu.sysprogs.org/portable/). Portable single exe-
cutable file runs under all versions of Microsoft Windows (10/8.1/8/7/2008/Vista/
2003/XP), on both x86 and x64 platforms. No system reboot is needed.
WinCDEmu is
1.6 Conclusion
In this chapter, we have tried to clearly describe the concept of a file, which is
fundamental for computer sciences, to classify them according to various features
and ways of using them. It is also important to understand what executable and batch
files are and the order in which executable files are launched.
Since we actively use virtual disks in the book, we have given a description of
programs and commands for creating them.
Software Installation
2
• Extracts the components of the software being installed form archive into a
temporary folder (usually TEMP)
• Copies extracted files into the appropriate location in the user’s computer
• Modifies the Windows system registry for some parameters
• Carries out system-wide and user-level changes for some parameters such as
PATH
• Creates system menu items and icons and desktop shortcuts for quick launch
Of course, not every Setup program does have to carry out every step of this
scenario.
Sometimes, on updating, some software requires removing (uninstalling) the old
version in order to proceed. Uninstalling software usually is quite straightforward
but sometimes may cause problems, especially in the case of big packages such as
Visual Studio. Notice that very often some registry items related to software being
uninstalled stay undeleted and may cause errors on reinstalling.
Note It is not a good practice to add the path to the executable file of the software
being installed into the environment variable PATH.
The most recent trends should be pointed out about the subject: more and more
software packages are distributed not only in the form of msi but also zip/7z
archives. In our opinion, this method is one of the most flexible and has the following
advantages:
This method is especially suitable for compilers since these kinds of software are
designed to work in the command line. Recall that compilers themselves have no
visual interface; they always work in the command line.
2.6 Best Software Installation Practices for Windows Systems 11
The most popular GCC C/C++ compiler also works under Windows operating
systems, and its port to these systems is called MinGW (Minimalist GNU for
Windows). MinGW can be downloaded as (in the form of) both source code and
zip/7z (sometimes, as self-extracting exe) archive packages.
Another installation way is installing from the source code of a software or library.
This way is the most flexible but complicated one.
The vast majority of Linux software are distributed with source code, together
with prebuilt binaries.
However, many libraries are provided only in source code (binaries may cause
compatibility issues on Linux systems), because usually it is easy to build from
sources. These libraries could also be built under Windows, with some additional
efforts.
Source code is written in high-level programming languages and should be
compiled using the compilers of these languages, so users have to have the
corresponding compilers installed in their system. We will discuss these topics
further.
Software packages distributed in the form of zip/7z archives can be burned into a
CD/DVD disk after extraction from the archive so that they can work directly from
CD/DVD.
It is even easier to write such programs to flash media and run from there. These
are examples of the so-called portable installation.
Now let’s talk about one installation method. This way looks somewhat complicated
for normal users since it takes some effort; however, it is done once, and the results
can be used many times afterward. Of course, these are only recommendations, not
strong rules, but they save time and effort in the future.
Our first recommendation is not to install software in system default locations,
such as C:\Program Files, except some software which require reinstalla-
tion after Windows reinstallation, such as Microsoft Office, Microsoft Visual Studio,
Adobe software, etc.
12 2 Software Installation
• Such kind of software requires fresh installation after Windows crash and
reinstallation.
• It cannot be installed without system administrator privileges.
• It cannot be copied or moved to another place without disruption.
• It cannot be copied or moved to removable media without disruption.
It is easy to launch the terminal window from any folder in the Linux graphical
interface without the need to explore using the cd command. For a long time,
this was not possible in Windows systems, but in the seventh version, such an
opportunity appeared. The user just has to right-click a folder icon while holding
the button (Figure 2-1).
However, many users are missing the ''Open command window here'' con-
text menu item in the Explorer window in later Windows versions because Microsoft
replaced it with a PowerShell launching item. PowerShell is too complicated for our
purposes for many reasons; we will not discuss it here.
We strongly advise to do as follows. On the second disk partition, say D:,
create the following folders: Programs, Soft, and User. These folders are to hold
programs, software archives downloaded, and user data, respectively. Why do we
store downloaded software in a place other than the default Downloads folder? The
answer is this: usually, the Downloads folder is cluttered with a bunch of garbage,
and it can be difficult to quickly find something there. In addition, in case of damage
to the C: drive or reinstalling Windows, as we said earlier, this data will remain intact
and can be reused. We will consider fine-tuning issues in the following chapters.
Sometimes, it is useful to change the drive letter assigned to a partition or
CD/DVD device. How to do this using the same Computer Management snap-in
is shown in Figure 2-2.
2.7 Conclusion
In this chapter, we have given an overview of the methods for installing software
on the Windows operating system. We looked at four ways to install software and
considered the advantages and disadvantages of each of them. At the end of the
chapter, our recommendations were given with the justification of our proposed
method of installing the software.
In view of their importance, we repeat our recommendations here with somewhat
more detailed justifications:
1. It is undesirable to have only one partition (disk) C: on your hard drive. When
purchasing a computer, you can ask to share your disk. This operation is not
difficult; you can do it yourself, with some experience, but it is better to ask a
guru you know. In any case, it is better to do this when your disk is still slightly
full, in which case the risks are minimal, and the process itself will take a little
time.
2.7 Conclusion 15
For the C: drive, in which the Windows system itself is located, it is enough
to allocate, say, 100 GB of space; the freed space can be allotted to the D: drive,
on which it is advisable to store data. The meaning of these actions is that if the
operating system breaks down (which happens quite often for various reasons:
viruses, illiterate user actions, etc.), your data will most likely remain intact and
will not be affected after the next reinstallation of Windows (recall that often,
when installing Windows, users completely format the C: drive, hoping to get rid
of viruses in this way).
2. Do not store data on the desktop! Do not store them in the so-called standard
folders like My Documents either—these folders are located by default in the
system partition (drive C:), and, if you are not a guru, then with such a breakdown
of Windows, when only the command line is available to you, you will not be able
to copy them. The data in such folders can be encrypted for security purposes,
which also adds to the problems in their recovery.
These problems can be avoided by storing data in the D: partition. Even if
you format the C: drive by mistake when reinstalling the system, your data will
remain intact. As for security, the users themselves can encrypt their data on the
D: drive.
Of course, the desktop is the very first place that comes to hand when you
need to quickly save something; however, as we have already shown, this is not
the best place. On the desktop, you only need to create shortcuts to folders with
data—the loss of shortcuts is not critical compared to the loss of data.
3. When creating directories (folders), avoid using national (and other non-English)
letters, as well as spaces! Until now, there are programs that incorrectly process
such paths. At best, such programs will crash, and at worst, they will behave
unpredictably, and the user risks wasting time looking for an unknown error.
Spaces in directory names are also undesirable because when working in
command-line mode, such paths have to be enclosed in (usually) double quotes,
which is very inconvenient. For this reason, do not install, for example, compilers
in the Program Files directory.
4. You should prefer such programs that do not require standard installation. The
reason is that they do not require installation, which saves time, and when
reinstalling the system, they do not need to be reinstalled. It should be noted that
such programs, as a rule, do not use the Windows system registry. Examples of
such programs are the Far Manager file and archive manager (http://farmanager.
com/), the popular VLC media player (www.videolan.org/vlc/), advanced text
editor Notepad++ (http://notepad-plus-plus.org/), various builds of the MinGW
compiler (porting the GCC compiler to Windows), and there are more and more
of them. Such programs are distributed in the form of an archive (zip, 7z, and
other formats); to install them, it is enough to unpack them into some directory.
There are several ways to customize the application, which are described in the
next sections
Currently, there are a large, if not huge, number of high-level languages; however,
when it comes to scientific and engineering computing, the choice narrows sharply,
literally to three (and in fact, to two) languages: C/C++ and good old Fortran.
3.2 C/C++
The C language was created in the early 1970s by Dennis Ritchie of AT&T Bell
Laboratories (Bell Labs) to write the Unix operating system. The C language has
had a huge impact on the computer industry: operating systems are written almost
entirely in this language, and many popular modern languages (C++, C#, Java,
JavaScript, and Objective-C) have actually borrowed its syntax.
Due to the presence of pointers in C, it is possible to write almost assembler
programs that are characterized by high execution speed. And at the same time, C is
much easier to write for most programmers than Fortran. Therefore, many modern
libraries for scientific and engineering calculations are already written in C, not in
Fortran.
The C language is standardized. In 1989, ANSI X3.159-1989 (ANSI C or C89)
was adopted. In 1990, the ANSI C standard was adopted, with a few modifications,
by the International Organization for Standardization (ISO) as ISO/IEC 9899:1990.
In 1999, the ISO 9899:1999 (C99) standard was adopted. In March 2000, it was
adopted and adapted by ANSI. On December 8, 2011, the new ISO/IEC 9899:2011
(C11) standard was published.
The canonical reference for the C language is the book by Brian Kernighan and
Dennis Ritchie The C Programming Language often cited as KR or K&R, originally
published in 1978 (by the way, it was in this book that the authors introduced the
tradition of writing as the first program in the target language a program that prints
the greeting “hello, world”, since then it has become an unwritten rule). The current
state of the language can be read in Ben Clemens’ book 21st Century C.
The C++ language was also created at AT&T Bell Laboratories, but by another
person—Bjarne Stroustrup, a Dane living and working in the United States. Its
original goal was to expand the C language by adding elements of object-oriented
programming there; for this reason, at first the new language was called C with
classes. In 1983, the language was renamed to C++ because it had grown from being
a simple extension of the C language—there were so many additions. But despite
all the changes, C++ remains compatible with the C language, with rare exceptions.
An important part of the C/C++ languages is the so-called standard library: for
example, C does not have a formatted output operator like write/writeln in
Pascal, but the printf function, which is found in the standard library. To use this
feature, you must include the corresponding header file. Similarly, the C++ standard
library includes not just input/output (I/O) classes and implementation functions
and classes of this kind (e.g., complex for working with complex numbers) but
also entire sublibraries of the STL type (STL, Standard Template Library, written
by Alexander Stepanov and has long become part of the language), including
sorting and searching algorithms. The language also provides work with strings and
regular expressions, with various data structures (dynamic arrays, linked lists, binary
trees, hash tables). In recent language implementations, classes for developing
multithreaded and parallel programs have been added to the standard library, support
for internationalization and classes for working with numbers (random numbers and
distributions, numeric functions) have been improved. In addition, there are a huge
number of utilities (e.g., clocks and timers).
Since 2012, C++ standards have been adopted on a three-year cycle. In 2020, the
ISO/IEC 14882:2020 standard, often referred to as C++20, was adopted, which is
the current one today. The C++23 standard is planned for this year (2023).
We recommend that you often look at https://cppreference.com, where you
can get not only comprehensive reference information but also code examples
illustrating the intricacies of using the element of the C++ language being studied.
We also recommend a number of books ([4] to [10]) on scientific programming that
use C and C++ to varying degrees.
The source code files of C programs have the .c extension, and the header files
have the .h extension. C++ files use .cpp and .cxx extensions, while header
files can have .hpp and .hxx extensions.
3.3 Fortran
Despite the seemingly solid old age (almost 60 years), the Fortran language is
not going to give up its positions at all: in 2010, the next Fortran 2008 language
standard was adopted, and work is actively underway on the next Fortran 2015
standard (a standard for programming languages alike, and for other areas, it is
very important—e.g., the Delphi language was not standardized, and its Pascal
3.4 Assembly 19
prototype has already three standards and even more implementations that are
incompatible between themselves; as a result, these languages are effectively dead).
The Fortran language (FORmula TRANslator) was developed at IBM in 1957 by
a group of specialists led by John Backus and was de facto the first high-level
algorithmic language (the first was the Plankalkul language, in German—calculus
plan, designed by the German engineer Konrad Zuse in 1945, but he did not have the
opportunity to implement his language; implementation completed only in 2000).
The main advantage of Fortran is the presence in the source code of care-
fully written, debugged, very efficient, and well-documented software packages
(libraries) for scientific and engineering calculations. A number of such libraries are
available commercially: NAG Numerical Library from The Numerical Algorithms
Group (NAG), IMSL Numerical Libraries (Rogue Wave Software), etc. These
libraries enjoy well-deserved prestige among specialists.
Another advantage of the Fortran language is the high speed of code execution.
In this parameter, Fortran is close to assembly language. Fortran is perhaps the
most standardized language: FORTRAN IV (FORTRAN 66, 1972), FORTRAN
77 (1980), Fortran 90 (1991), Fortran 95 (1997), Fortran 2003 (ISO/IEC 1539-
1:2004), Fortran 2008 (ISO/IEC 1539-1:2010). The language is actively developing;
for example, the Fortran 90 standard introduced a free format for writing code, as
well as elements of object-oriented programming, which were further developed in
the Fortran 2003 standard (in fact, the list of innovations is huge: actually, this is
like a new language; for those who studied the classical version of the language, the
amount of changes can be assessed only by studying the new standard). In the latest
versions of the standards, a lot of attention is paid to parallel computing.
3.4 Assembly
Assembly language allows you to create the shortest and fastest programs, but the
price of this is the large size of the source code. From this point of view, the use of
this language is inefficient, since it requires a lot of labor. However, this language has
its own niche—where you need a small code size and high speed of its execution.
Therefore, assembly code is used when writing drivers, as well as when writing
some components of the operating system that closely interacts with the hardware,
the so-called HAL (hardware abstraction layer).
One of the most common assemblers for Windows is the Microsoft Macro
Assembler (MASM), which is part of the Microsoft C/C++ compiler. It must be
emphasized that MASM is not supplied separately. We will briefly consider working
with it in subsequent chapters.
Assembly source code files have the extension .asm.
20 3 Programming Languages and Software
3.5 C#
Here are some extremely interesting quotes from Joseph Albahari and Ben
Albahari’s book C# 5.0 in a Nutshell, Fifth Edition [3]. They concern the use of
the C# language in calculations. First, let’s clarify some definitions of the basic
types used in calculations. These are quotes from [3, page 24]:
Of the real number types, float and double are called floating-point types and are
typically used for scientific calculations. The decimal type is typically used for financial
calculations, where base-10–accurate arithmetic and high precision are required.
Finally, we will quote in full from the short subsection Real Number Rounding
Errors [3, page 30]:
(as well as its factors, base 2 and base 5). Since real literals are in base 10, decimal can
precisely represent numbers such as 0.1. However, neither double nor decimal can
precisely represent a fractional number whose base 10 representation is recurring:
decimal m = 1M / 6M; // 0.1666666666666666666666666667M
double d = 1.0 / 6.0; // 0.16666666666666666
This leads to accumulated rounding errors:
decimal notQuiteWholeM = m+m+m+m+m+m; //
→ 1.0000000000000000000000000002M
double notQuiteWholeD = d+d+d+d+d+d; // 0.99999999999999989
which breaks equality and comparison operations:
Console.WriteLine (notQuiteWholeM == 1M); // False
Console.WriteLine (notQuiteWholeD < 1.0); // True
As an illustration, we give the texts of the simplest programs in C#1 and C++,
CSharp.cs and CPP.cpp, which implement a simple algorithm: the difference
1.0 − 0.1 ∗ 10
.
is calculated and then the result is displayed on the screen (Figures 3-1 and 3-2).
Note that the rather strange result of this C# program was tested in Windows
7, for the .NET Framework versions 2.0, 3.5 and 4.0. There is no such error in
Windows 10.
3.6 Conclusion
In this chapter, we have given a brief overview of the C/C++ and Fortran languages
and also provided important information about the C# language regarding compu-
tational aspects.
We also mentioned assembly language in the Microsoft implementation—
Microsoft Macro Assembler (MASM).
General Build Information
4
This chapter describes the process of building software on Unix-like and Windows
systems. A way to port the build process on Unix systems to the Windows platform
is given. New build tools in Windows are also given.
The traditional tool for building programs and libraries in the world of Unix-like
systems is the famous make utility. Depending on what the utility is “ordered” to
do, it can do many things: compile files, create object files from them, build a library
from them, or, by linking them with runtime libraries, create an executable file and
place them in the specified directories in the system.
For all these purposes, the make utility calls the appropriate programs: the
compiler is called to compile, the archiver is called to create archived libraries, and
the linker is called for linking. make reads all these instructions from a special file
called Makefile.
Makefile is a text file of a special format; for simple projects, it can be created
manually; for large projects, there are automated tools creating such files.
Note The Makefile must reside in the root directory of the project.
make is guided by the rule in order to build the target file from the source files of
the project. A target is usually the name of executable or object files; it can also be
the name of an action to carry out. Examples of the latter are 'all', 'clean',
'install', and 'uninstall'; they are called 'Phony Targets' and
are marked by .PHONY in Makefile. Usual targets may depend on several files.
Note Failure to follow the Makefile format (often incorrect indentation at the
beginning of a line in the description of targets) leads to an error in the make utility.
The basic sequence of commands for building programs and libraries with some
variations comes down to the following:
$ ./Configure
$ make
# make install
4.2 Windows Systems 25
For some libraries (e.g., for GMP), the stage of checking the built result is desirable,
which is made by the command
$ make check
Options:
D:\Users\John>
When developing modern software, especially large software, the so-called inte-
grated development environments (IDEs) are used, which include not only high-
level language compilers but also debuggers to facilitate finding errors in programs
and optimizing their work, as well as advanced source code editors with syntax
highlighting and auto-completion functions and an advanced hint system, a system
for working with source code repositories and version control, a designer for
designing a graphical interface. Some environments contain database tools.
Of course, the source code of such applications consists of many files, and they
are usually combined into so-called Projects. The source code of such Projects
consists not only of files in some high-level programming language but also of
resource files (icons, images, audio and video, etc.) and settings files—up to the
cursor position in a specific file opened in the source code editor. Projects are created
in the IDE (of course, very simple Projects can be created by hand, following the
appropriate file formats, but this is usually not necessary), and each IDE has its own
format. Typically, IDE project files are XML files (text files with Unicode support).
Microsoft Visual Studio project files have the .vcxproj extension (for older
versions of Visual Studio, .vcproj). Visual Studio projects can be grouped into
so-called Solutions, which consist of multiple .vcxproj projects. It is interesting
to note that Solutions can combine projects written in different programming
languages. Solutions files have the extension .sln.
To build Visual Studio projects and solutions, MSBuild is a utility that is tightly
integrated into Visual Studio and is currently its native build system. However, we
note that it is not necessary to use MSBuild from the Visual Studio environment to
build projects and solutions—MSBuild can be run from the command line too.
Undoubtedly, projects make life easier when developing complex programs,
especially those with a visual interface. However, in practice, especially in academic
and scientific environments, you have to write programs that consist of a single
file (or a small number of files), and creating a project for such programs does not
make much sense. It is also important to emphasize that projects are generally not
cross-platform—they cannot be ported to another platform or operating system. For
researchers (and not only for them), this situation is not acceptable: for example,
having written an implementation of some algorithm in the standard C++ language,
the author wants to test the program on different platforms and operating systems.
For the preceding reasons, the ability of development environments to compile
individual files is important. As far as we know, in recent years, the developers of
Microsoft Visual Studio have also paid attention to this.
Random documents with unrelated
content Scribd suggests to you:
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com