| PSHOT-ENG — Build Your Own 3D Engine in ISO C89 | Contents | Chapter 02 | Going Further |
Install GCC, Make, SDL 1.2 headers, and clangd on Linux Mint, then verify VSCodium autocomplete and the project layout.
| Chapter: | 00 Duration: 20 min |
| Files: | Makefile, compile_flags.txt |
| Concepts: | ISO C89 flags, SDL 1.2 headers, clangd, Flatpak sandbox paths |
| On this page: | Packages · Project Tree · Makefile · VSCodium + clangd · Exercises · Recap |
Open a terminal and install the C compiler, Make, SDL 1.2 development headers, and the clangd language server:
| Terminal (bash) |
sudo apt update sudo apt install build-essential libsdl1.2-dev clangd |
Keep the repository flat and predictable. Every `.c` and `.h` file lives inside src/, while build files sit in the root pshot/ directory:
| Directory Tree (text) |
pshot/
Makefile
compile_flags.txt
src/
types.h
platform.h
platform.c
main.c |
We compile with -std=c89 -Wall -Wextra -pedantic so modern GCC catches any C99/GNU extension that would break older compilers or retro Windows toolchains. Notice $(OBJS) in the clean rule so object files are always wiped cleanly.
| Makefile (makefile) |
CC = gcc CFLAGS = -std=c89 -Wall -Wextra -pedantic -Wno-long-long -O2 -Isrc $(shell sdl-config --cflags) LDFLAGS = $(shell sdl-config --libs) -lm TARGET = pshot SRCS = src/main.c src/platform.c OBJS = $(SRCS:.c=.o) all: $(TARGET) $(TARGET): $(OBJS) $(CC) $(OBJS) -o $(TARGET) $(LDFLAGS) src/%.o: src/%.c $(CC) $(CFLAGS) -c $< -o $@ run: $(TARGET) ./$(TARGET) clean: rm -f $(OBJS) $(TARGET) .PHONY: all run clean |
| Pitfall: Spaces vs. Tabs in Makefile Make requires literal TAB characters before recipe lines (such as $(CC) ...). If you see missing separator, switch VSCodium’s bottom-right indicator from Spaces: 4 to Indent Using Tabs while editing Makefile. |
Install the clangd extension (by llvm-vs-code-extensions) from Open VSX inside VSCodium, then place compile_flags.txt in your project root right next to Makefile:
| compile_flags.txt (text) |
-std=c89 -Wall -Wextra -pedantic -Isrc -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT |
| Pitfall: Flatpak VSCodium Header Paths If VSCodium was installed via Linux Mint’s Software Manager as a Flatpak, host headers are mounted under /run/host/usr/include instead of /usr/include. Change the include line in compile_flags.txt to -I/run/host/usr/include/SDL and run clangd: Restart language server from the Command Palette. |
sdl-config --cflags --libs in your terminal and read the exact flags your Makefile injects.clangd --version works from VSCodium’s integrated terminal.-std=c89 -pedantic enforces portable ANSI/ISO C89 across Linux and retro Windows toolchains.compile_flags.txt teaches clangd where SDL.h lives, one flag per line.platform.c (and later audio.c) will ever include SDL.h.| « Contents | Table of Contents | Ch 01: Platform Layer » |