This repository gathers C++ code examples coming from various websites and books. It also includes build scripts (bash scripts, batch files, Make scripts) for experimenting with C++ on a Windows machine. |
Ada, Akka, COBOL, Dafny, Dart, Deno, Docker, Erlang, Flix, Golang, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Scala 3, Spark, Spring, TruffleSqueak, WiX Toolset and Zig are other topics we are continuously investigating.
☛ Read the document "History of C++" to get a quick overview of the evolution of C++.
This project depends on the following external software for the Microsoft Windows platform:
- CMake 3.31 (release notes)
- Git 2.47 (release notes)
- LLVM 17 1 (release notes)
- MSYS2 2024 1 2 (changelog)
- oneAPI DPC++ 2024 1 (release notes)
- Visual Studio Community 2019 1 (release notes)
- Windows SDK 10 (release notes)
Optionally one may also install the following software:
- Bazel 7.4 LTS (release notes)
- ConEmu 2023 (release notes)
- Doxygen 1.12 (changelog)
- Embarcadero C++ 7.30 Compiler
- LLVM 19 (release notes)
- OrangeC 6.73 (release notes)
- Visual Studio Code 1.95 (release notes)
- Visual Studio Community 2022 1 (release notes)
☛ Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we definedC:\opt\
as the installation directory for optional software tools (in reference to the/opt/
directory on Unix).
For instance our development environment looks as follows (December 2024) 3:
C:\opt\bazel\ ( 51 MB) C:\opt\BCC-10.2\ (194 MB) C:\opt\cmake\ (112 MB) C:\opt\ConEmu\ ( 26 MB) C:\opt\doxygen\ (120 MB) C:\opt\Git\ (367 MB) C:\opt\LLVM-17.0.6\ (3.1 GB) C:\opt\LLVM-19.1.3\ (2.0 GB) C:\opt\msys64\ (2.8 GB) C:\opt\orangec\ ( 74 MB) C:\opt\VSCode\ (341 MB) C:\Program Files\Microsoft Visual Studio\2022\Community\ (4.4 GB) C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\ (4.2 GB) C:\Program Files (x86)\Intel\oneAPI\ (3.3 GB) C:\Program Files (x86)\Windows Kits\10\ (6.7 GB)
🔎 Git for Windows provides a BASH emulation used to run
git.exe
from the command line (as well as over 250 Unix commands likeawk
,diff
,file
,grep
,more
,mv
,rmdir
,sed
andwc
).
Directory structure ▴
This project is organized as follows:
bin\ concurrency-examples\{README.md, acquireConsume, etc.} dmc3-examples\{README.md, cpp20_algebraic_concepts, etc.} docs\ examples\{README.md, call-by-copy, class-dispatching, etc.} grimm-examples\{README.md, templateMethod, visitor, etc.} gui-examples\{README.md, simple-window, etc.} pthreads-examples\{README.md, fib, myTurn, etc.} README.md RESOURCES.md setenv.bat
where
- directory
bin\
contains utility tools. - directory
concurreny-examples
contains C++ code examples from Grimm's book (seeREADME.md
file). - directory
docs\
contains C++ related papers/articles. - directory
examples\
contains C++ code examples (seeREADME.md
file). - directory
grimm-examples
contains C++ code examples from Grimm's website (seeREADME.md
file). - directory
gui-examples
contains C++ code examples depending on the Win32 API. - directory
pthreads-examples\
contains C++ code examples (seeREADME.md
file). - file
README.md
is the Markdown document for this page. - file
RESOURCES.md
is the Markdown document presenting external resources. - file
setenv.bat
is the batch script for setting up our environment.
Batch commands ▴
setenv.bat
4
We execute command setenv
once to setup our development environment; it makes external tools such as bazel.exe
, git.exe
and sh.exe
directly available from the command prompt.
> setenv Tool versions: bazel 7.4.1, bcc32c 7.30, clang 17.0.6, gcc 13.2.0, icx 2024.2.1, occ 6.73.8 cmake 3.31.1, cl 19.36.33523, cppcheck 2.16.0, doxygen 1.12.0, msbuild 17.11.2.32701 git 2.47.0, diff 3.10, bash 5.2.37(1) > where bazel git sh C:\opt\bazel\bazel.exe C:\opt\Git\bin\git.exe C:\opt\Git\mingw64\bin\git.exe C:\opt\Git\bin\sh.exe C:\opt\msys64\usr\bin\sh.exe C:\opt\Git\usr\bin\sh.exe
Command setenv help
displays the help messsage :
> setenv help Usage: setenv { <option> | <subcommand> } Options: -bash start Git bash shell instead of Windows command prompt -debug print commands executed by this script -verbose print progress messages Subcommands: help print this help message
Footnotes ▴
[1] C++ Compilers ↩
- The installed development tools for Windows give us access to the following C++ compilers:
-
Devtool C++ Compiler Version ISO Standards a) Embarcadero bcc32c.exe
7.30 11 LLVM clang.exe
17.0.x 98, 11, 14, 17, 20, 2b b) MSVS
(Microsoft)cl.exe
19.41.34120 14, 17, 20 MSYS2 g++.exe
13.3.0 98, 11, 14, 17, 20, 23 b) oneAPI
(Intel)icx.exe
2024.2.1 11, 14, 17, 20 OrangeC
(LADSoft)occ.exe
6.73 11, 14 a) Standard specified with compiler option, e.g.-std=c++17
; starting with version 2023.0 oneAPI uses C++17 as the default C++ language.
b) ISO standard 23 partially supported.
[2] Cppcheck ↩
-
Cppcheck for Windows is available either as Windows installer or as MSYS2 package.
Since our project depends on MSYS2 we choose to install the MSYS2 package
mingw-w64-x86_64-cppcheck
:> %MSYS_HOME%\usr\bin\pacman.exe -Ss cppcheck clangarm64/mingw-w64-clang-aarch64-cppcheck 2.16.0-1 static analysis of C/C++ code (mingw-w64) mingw64/mingw-w64-x86_64-cppcheck 2.16.0-1 [installed] static analysis of C/C++ code (mingw-w64) ucrt64/mingw-w64-ucrt-x86_64-cppcheck 2.16.0-1 static analysis of C/C++ code (mingw-w64) clang64/mingw-w64-clang-x86_64-cppcheck 2.16.0-1 static analysis of C/C++ code (mingw-w64) > %MSYS_HOME%\usr\bin\pacman.exe -Syu mingw-w64-x86_64-cppcheck :: Synchronizing package databases... [...] Packages (10) less-643-1 libgnutls-3.8.1-1 mingw-w64-x86_64-bzip2-1.0.8-2 mingw-w64-x86_64-gcc-13.2.0-2 mingw-w64-x86_64-gcc-ada-13.2.0-2 mingw-w64-x86_64-gcc-libs-13.2.0-2 mingw-w64-x86_64-headers-git-11.0.0.r107.gd367cc9d7-2 mingw-w64-x86_64-pcre-8.45-1 mingw-w64-x86_64-wineditline-2.206-1 mingw-w64-x86_64-cppcheck-2.16.0-1 Total Installed Size: 388.66 MiB Net Upgrade Size: 20.34 MiB :: Proceed with installation? [Y/n] :: Retrieving packages... [...] > where /r %MSYS_HOME% cppcheck.exe C:\opt\msys64\mingw64\bin\cppcheck.exe
-
Reminder: How we created our MSYS2 installation (installation directory:
MSYS_HOME=C:\opt\msys64
) :Executed command Used size (MB) msys2-x86_64-20240727.exe
304 %MSYS_HOME%\usr\bin\pacman.exe -S make
310 %MSYS_HOME%\usr\bin\pacman.exe -S gcc
798 %MSYS_HOME%\usr\bin\pacman.exe -S automake
812 %MSYS_HOME%\usr\bin\pacman.exe -S mingw-w64-x86_64-cppcheck
843 %MSYS_HOME%\usr\bin\pacman.exe -S texinfo
854 (to be updated) ..
[3] Downloads ↩
- In our case we downloaded the following installation files (see section 1):
-
bazel-7.4.1-windows-x86_64.zip ( 50 MB) BCC102.zip (Embarcadero) ( 45 MB) cmake-3.31.1-windows-x86_64.zip ( 38 MB) ConEmuPack.230724.7z ( 5 MB) LLVM-17.0.6-win64.exe (263 MB) LLVM-19.1.3-win64.exe (336 MB) msys2-x86_64-20240727.exe ( 86 MB) PortableGit-2.47.1-64-bit.7z.exe ( 46 MB) VSCode-win32-x64-1.95.3.zip (131 MB) w_dpcpp-cpp-compiler_p_2024.2.1.83_offline.exe (1.2 GB) winsdksetup.exe (1.3 MB) ZippedBinaries6738.zip (OrangeC) ( 22 MB)
[4] setenv.bat
usage ↩
-
setenv.bat
has specific environment variables set that enable us to use command-line developer tools more easily. - It is similar to the setup scripts described on the page "Visual Studio Developer Command Prompt and Developer PowerShell" of the Visual Studio online documentation.
-
For instance we can quickly check that the two scripts
Launch-VsDevShell.ps1
andVsDevCmd.bat
are indeed available in our Visual Studio 2019 installation :> where /r "C:\Program Files (x86)\Microsoft Visual Studio" *vsdev* C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_start.bat
-
Concretely, in our GitHub projects which depend on Visual Studio (e.g.
michelou/cpp-examples
),setenv.bat
does invokeVsDevCmd.bat
(resp.vcvarall.bat
for older Visual Studio versions) to setup the Visual Studio tools on the command prompt.