Kompilation Mit Unix
← Standard Datei Deskriptoren | ● | Kompilation mit CMake →
Kommandozeile bei einem Modul (nur Main):
cc main.c -o main -lm # compile and link main module
Kommandozeile bei mehreren Modulen:
cc -c moduleA.c -o moduleA.o # compile module A cc -c moduleB.c -o moduleB.o # compile module B ... cc -c main.c -o main.o # compile main cc main.o moduleA.o moduleB.o ... -o main -lm -l... # link
Erstellen eines Archivs:
ar -crs libName.a moduleA.o moduleB.o ...
Mit dem Archiv linken:
cc main.o -o main -lm -lName -l...
Mit Makefiles oder CMake bzw. MSVC bewerkstelligt man obige Aufgabe komfortabler in einem einzigen Schritt, d.h. es werden alle Module auf einmal kompiliert und anschliessend automatisch gelinkt. Zudem wird ein Modul nur dann neu kompiliert, wenn der entsprechende Quellcode nicht verändert wurde.
Weitere Informationen zu Makefiles und CMake im GCC Tutorial.