class: lead
Introduction pratique, pas-à-pas, avec des diagrammes explicatifs
Makefile
hello.c
#include <stdio.h> int main(void) { printf("Bonjour, monde!\n"); return 0; }
Ce diagramme montre les étapes du code source jusqu'à l'exécutable. Astuce : ouvrez diagrams/compile_workflow.svg séparément pour voir les détails si besoin.
diagrams/compile_workflow.svg
sudo apt update
sudo apt install build-essential make binutils
sudo apt install gdb valgrind
sudo apt install cppcheck clang-tidy clang-format
sudo apt install clang
gcc --version ; gdb --version ; valgrind --version
gcc hello.c -o hello
./hello
Bonjour, monde!
Explication visuelle des flags courants (-Wall, -Wextra, -g, -O2, -std=c11).
-Wall
-Wextra
-g
-O2
-std=c11
CC=gcc CFLAGS=-Wall -Wextra -std=c11 -g hello: hello.o $(CC) $(CFLAGS) hello.o -o hello hello.o: hello.c $(CC) $(CFLAGS) -c hello.c -o hello.o clean: rm -f hello hello.o
Visualise les dépendances entre cibles et fichiers objets. Astuce : ouvre diagrams/makefile_flow_lr.svg séparément pour voir la version détaillée.
diagrams/makefile_flow_lr.svg
gcc -g -O0 hello.c -o hello
sudo apt install gdb valgrind cppcheck
gdb ./hello
break main
run
step
next
bt
print var
valgrind --leak-check=full ./hello
cppcheck --enable=all .
clang-tidy
clang-format
clang-tidy hello.c --
clang-format -i hello.c
Résumé visuel : compiler avec -g, utiliser gdb, puis valgrind si besoin.
gdb
valgrind
clean
man gcc
man gdb
cppcheck
Bonne compilation!