Contents
Getting started
apt install vim gcc g++ gcc-doc
Hello World - C
Erstellen einer Datei main.c mit folgendem Inhalt:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { printf("Hallo\n"); return EXIT_SUCCESS; }
Kompilieren: gcc -o test main.c
Ausführen: ./test
user@host:~$ ./test Hallo user@host:~$
Hello World - C++
Erstellen einer Datei main.cpp mit folgendem Inhalt:
#include <cstdlib> #include <iostream> int main(int argc, char *argv[]) { std::cout << "Hallo" << std::endl; return EXIT_SUCCESS; }
Kompilieren: g++ -o test main.cpp
Ausführen: ./test
user@host:~$ ./test Hallo user@host:~$
Parameterabfrage der main-Funktion
user@host:~$ ./test param1 param2 param3 Index: 0 - ./test Index: 1 - param1 Index: 2 - param2 Index: 3 - param3 user@host:~$
Wichtige Compiler Parameter
Parameter |
Beschreibung |
-o |
Ausgabedatei |
-g |
Extra Informationen für Debugging |
-Og |
Optimierung für debugging |
-Wpedantic |
siehe: gcc --help=warnings |
-Wall |
siehe: gcc --help=warnings |
-Wextra |
siehe: gcc --help=warnings |
-std= |
standard |
-E |
Nicht compilieren |
-S |
Nicht assemblen |
-c |
Compilieren, aber nicht linken |
Das Kompilieren
Die Compiler Parameter -c, -S und -E geben dem Compiler an, an welchem Schritt vom Kompilerprozess der Compiler stoppen soll.
- gcc -E main.c - Beendet nach dem preprocessing und gibt das Ergebnis auf der Standardausgabe aus
- gcc -S main.c - Erzeugt eine main.s mit assembler code
- gcc -c main.c - Erzeugt eine main.o, aber linked nicht