- Setting up development on Windows has traditionally been extremely painful.
- To combat this, there are a number of Powershell scripts that install the necessary packages/software
This first script installs the following :-
- git
- winget
- chocolatey
- Windows Terminal
- WizFile
- CMake
- Geany and Geany Plugins
- winlibs
- conan
- Meson
irm https://learncodethehardway.com/setup/base.ps1 -outfile base.ps1
powershell -executionpolicy bypass .\base.ps1
irm https://learncodethehardway.com/setup/cpp.ps1 -outfile cpp.ps1
powershell -executionpolicy bypass .\cpp.ps1
To test this, run the following :-
git clone https://git.learnjsthehardway.com/learn-code-the-hard-way/game-dev-starter-pack.git
cd game-dev-starter-pack
powershell -executionpolicy bypass .\scripts\setup.ps1
meson compile -C builddir
.\builddir\sfmldemo
A basic meson.build
file looks like this :-
project('learn-cpp-the-hard-way', 'cpp',
default_options: ['cpp_std=c++20'])
executable('ex02', 'ex02.cpp')
To configure a build directory, use this command:
meson setup --reconfigure builddir
To build everything using Meson, use this command:
meson compile -C builddir
To clean your build first, run this before the above:
meson compile --clean -C builddir
- or -
rm -recurse -force builddir
meson setup --reconfigure builddir
- use
cout
to output to standard output - use
cerr
to output to error output
Convert a number to a string using the std::to_string()
function
There are a number of functions to convert strings back to their number types as follows :-
std::stoi
- String to intstd::stol
- String to longstd::stoll
- String to long longstd::stoul
- String to unsigned longstd::stoull
- String to unsigned long longstd::stof
- String to floatstd::stod
- String to doublestd::stold
- String to long double
To add a dependency, in this case fmt
, to Meson, add this line below the project() part.
fmt = dependency('fmt')
Then add this as the third parameter of the executable
call, as such.
executable('ex09', 'ex09.cpp', dependencies: fmt)
The next thing you need to do is get Meson to download fmt
mkdir subprojects
meson wrap install fmt
Currently, our builds are set up to use dynamic linking, but we need static linking.
Dynamic linking is where your program doesn't actually contain the code for the fmt
library, instead it references a .so
, .dylib
, or .dll
file on your computer. The problem with this is it requires your program knows where all these libraries are located.
To enable static linking, you need to rebuild your builddir
with a new configuration
rm -recurse -force builddir
meson setup --prefer-static --default-library=static builddir
meson compile -C builddir