michelou / cpp-examples

Playing with C++ on Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Playing with C++ on Windows

ISO C++ project This repository gathers C++ code examples coming from various websites and books.
It also includes build scripts (batch files, Make scripts) for experimenting with ISO C++ on a Windows machine.

Ada, Akka, COBOL, Dart, Deno, Docker, Flix, Golang, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Scala 3, Spark, Spring, TruffleSqueak and WiX Toolset are other topics we are continuously investigating.

Project dependencies

This project depends on the following external software for the Microsoft Windows platform:

Optionally one may also install the following software:

Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we defined C:\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 (April 2024) 3:

C:\opt\bazel\                            ( 51 MB)
C:\opt\BCC-10.2\                         (194 MB)
C:\opt\cmake\                            (112 MB)
C:\opt\doxygen\                          (120 MB)
C:\opt\Git\                              (367 MB)
C:\opt\LLVM-17.0.6\                      (3.1 GB)
C:\opt\msys64\                           (2.8 GB)
C:\opt\orangec\                          ( 74 MB)
C:\opt\VSCode\                           (341 MB)
c:\Program Files\Cppcheck\               ( 35 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 like awk, diff, file, grep, more, mv, rmdir, sed and wc).

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

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.1.1, bcc32c 7.30, clang 17.0.6, gcc 13.2.0, icx 2024.0.2, occ 6.73.8
   cmake 3.29.0, cl 19.36.32532, cppcheck 2.13.0, doxygen 1.10.0, msbuild 17.7.2.37605
   git 2.44.0.windows.1, diff 3.10, bash 5.2.26(1)-release

> 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:
DevtoolC++ CompilerVersionISO Standards a)
Embarcaderobcc32c.exe7.3011
LLVMclang.exe17.0.x98, 11, 14, 17, 20, 2b b)
MSVS
(Microsoft)
cl.exe19.36.3253214, 17, 20
MSYS2g++.exe13.2.098, 11, 14, 17, 20, 23 b)
oneAPI
 (Intel)
icx.exe 2024.0.2 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
mingw32/mingw-w64-i686-cppcheck 2.13.1-1
    static analysis of C/C++ code (mingw-w64)
mingw64/mingw-w64-x86_64-cppcheck 2.13.1-1
    static analysis of C/C++ code (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-cppcheck 2.13.1-1
    static analysis of C/C++ code (mingw-w64)
clang32/mingw-w64-clang-i686-cppcheck 2.13.1-1
    static analysis of C/C++ code (mingw-w64)
clang64/mingw-w64-clang-x86_64-cppcheck 2.13.1-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.13.1-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

[3] Downloads

In our case we downloaded the following installation files (see section 1):
bazel-7.1.1-windows-x86_64.zip                  ( 49 MB)
BCC102.zip (Embarcadero)                        ( 45 MB)
cmake-3.29.0-windows-x86_64.zip                 ( 38 MB)
w_dpcpp-cpp-compiler_p_2024.0.2.28_offline.exe  (1.2 GB)
LLVM-17.0.6-win64.exe                           (263 MB)
msys2-x86_64-20240113.exe                       ( 86 MB)
PortableGit-2.44.0-64-bit.7z.exe                ( 46 MB)
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 and VsDevCmd.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 invoke VsDevCmd.bat (resp. vcvarall.bat for older Visual Studio versions) to setup the Visual Studio tools on the command prompt.

mics/April 2024  

About

Playing with C++ on Windows


Languages

Language:C 72.1%Language:C++ 27.9%