Lets start with a simple “Hello World”
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Now we have two popular compiler suites
- GCC and
- LLVM
For GCC the next steps are
gcc -c hello.c
gcc -o hello hello.o
For LLVM alternatively as follows
clang -c hello.c
clang -o hello hello.o
And a respective Make file looks like the following
CC = clang
CFLAGS = -Wall
all: hello
hello: hello.o
$(CC) $(CFLAGS) -o hello hello.o
hello.o: hello.c
$(CC) $(CFLAGS) -c hello.c
clean:
rm -f hello hello.o
For C++ the program looks like the following
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
Compiling and linking via GCC
g++ -o hello hello.cpp
Via LLVM as follows
clang++ -o hello hello.cpp
Debuggern happens via
GCC
gbd
And LLVM
lldb