Misc fixes; Update index; Add meson to compiling note

This commit is contained in:
2025-04-14 15:08:48 +01:00
parent e31873989d
commit 1fd800abf1
6 changed files with 241 additions and 96 deletions

View File

@@ -64,16 +64,50 @@ gcc -o hello hello.c -lcs50
## Make
`Make` Is a build automation tool that automates the process of compiling, linking and building executables.
An example `Makefile` could look like the following:
An example `Makefile` (for an app using `GTK4`) could be as follows:
```Makefile
hello:
gcc -o hello hello.c -lcs50
CC = gcc
CFLAGS = $(shell pkg-config --cflags gtk4)
LIBS = $(shell pkg-config --libs gtk4)
hello: hello.c
$(CC) $(CFLAGS) -o hello hello.c $(LIBS) -O2
debug: hello.c
$(CC) $(CFLAGS) -o hello hello.c $(LDFLAGS) -Wall -Wextra -Og -g
clean:
rm -f hello
```
```Shell
make # Compiles hello.c
make debug # Compiles hello.c using debug flags
make clean # Removes the executable (hello) generated by the make command.
```
## Meson
While `make` automates compiling, on larger projects, makefiles can grow hard to read quickly, and dependency resolution has to be done using external tools (such as `pkg-config`).
Meson is a more modern alternative, which is faster, and uses declarative syntax (describe *what* to build, instead of *how* to build it). Meson can automatically manage dependencies, header files, and compiler flags.
When `meson` is executed, it generates a `ninja.build` file, which is then parsed by `ninja`, a lower-level build tool.
```meson.build
project('hello', 'c')
gtk4_dep = dependency('gtk4')
executable('hello', 'hello.c',
dependencies: gtk4_dep)
```
```bash
mkdir build
meson setup build # Generate files for Ninja in the build dir
meson compile -C build # Compile the project (same as `ninja -C build`)
./build/hello
ninja clean -C build # Clean executable files in the build directory
```