--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -37,78 +37,78 @@
 pthread: $(ALL_PTHREAD)
 
 otf2_reader_example.o: otf2_reader_example.c
-	gcc -std=c99 `otf2-config --cflags` \
+	$(CC) $(CFLAGS) -fPIC -std=c99 `otf2-config --cflags` \
             -c otf2_reader_example.c \
             -o otf2_reader_example.o
 
 otf2_reader_example: otf2_reader_example.o
-	gcc otf2_reader_example.o \
+	$(CC) $(CFLAGS) $(LDFLAGS) -fPIE otf2_reader_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_reader_example
 
 otf2_writer_example.o: otf2_writer_example.c
-	gcc -std=c99 `otf2-config --cflags` \
+	$(CC) $(CFLAGS) -fPIC -std=c99 `otf2-config --cflags` \
             -c otf2_writer_example.c \
             -o otf2_writer_example.o
 
 otf2_writer_example: otf2_writer_example.o
-	gcc otf2_writer_example.o \
+	$(CC) $(CFLAGS) $(LDFLAGS) -fPIE otf2_writer_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_writer_example
 
 otf2_mpi_reader_example.o: otf2_mpi_reader_example.c
-	mpicc -std=c99 `otf2-config --cflags` \
+	$(MPICC) $(CFLAGS) -fPIC -std=c99 `otf2-config --cflags` \
             -c otf2_mpi_reader_example.c \
             -o otf2_mpi_reader_example.o
 
 otf2_mpi_reader_example: otf2_mpi_reader_example.o
-	mpicc otf2_mpi_reader_example.o \
+	$(MPICC) $(CFLAGS) $(LDFLAGS) -fPIE otf2_mpi_reader_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_mpi_reader_example
 
 otf2_mpi_reader_example_cc.o: otf2_mpi_reader_example.cc
-	mpic++ `otf2-config --cflags` \
+	$(MPICXX) $(CXXFLAGS) -fPIC \
             -c otf2_mpi_reader_example.cc \
             -o otf2_mpi_reader_example_cc.o
 
 otf2_mpi_reader_example_cc: otf2_mpi_reader_example_cc.o
-	mpic++ otf2_mpi_reader_example_cc.o \
+	$(MPICXX) $(CXXFLAGS) $(LDFLAGS) -fPIE otf2_mpi_reader_example_cc.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_mpi_reader_example_cc
 
 otf2_mpi_writer_example.o: otf2_mpi_writer_example.c
-	mpicc -std=c99 `otf2-config --cflags` \
+	$(MPICC) $(CFLAGS) -fPIC -std=c99 `otf2-config --cflags` \
             -c otf2_mpi_writer_example.c \
             -o otf2_mpi_writer_example.o
 
 otf2_mpi_writer_example: otf2_mpi_writer_example.o
-	mpicc otf2_mpi_writer_example.o \
+	$(MPICC) $(CFLAGS) $(LDFLAGS) -fPIE otf2_mpi_writer_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_mpi_writer_example
 
 otf2_openmp_writer_example.o: otf2_openmp_writer_example.c
-	gcc -std=c99 -fopenmp `otf2-config --cflags` \
+	$(CC) $(CFLAGS) -fPIC -std=c99 -fopenmp `otf2-config --cflags` \
             -c otf2_openmp_writer_example.c \
             -o otf2_openmp_writer_example.o
 
 otf2_openmp_writer_example: otf2_openmp_writer_example.o
-	gcc -fopenmp otf2_openmp_writer_example.o \
+	$(CC) $(CFLAGS) $(LDFLAGS) -fPIE -fopenmp otf2_openmp_writer_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_openmp_writer_example
 
 otf2_pthread_writer_example.o: otf2_pthread_writer_example.c
-	gcc -std=c99 -pthread `otf2-config --cflags` \
+	$(CC) $(CFLAGS) -fPIC -std=c99 -pthread `otf2-config --cflags` \
             -c otf2_pthread_writer_example.c \
             -o otf2_pthread_writer_example.o
 
 otf2_pthread_writer_example: otf2_pthread_writer_example.o
-	gcc -pthread otf2_pthread_writer_example.o \
+	$(CC) $(CFLAGS) $(LDFLAGS) -fPIE -pthread otf2_pthread_writer_example.o \
             `otf2-config --ldflags` \
             `otf2-config --libs` \
             -o otf2_pthread_writer_example
