Compiling with GCC; following programs are given, compile and link.
http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/main.cmain.c
http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/reciprocal.cppreciprocal.cpp
http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/reciprocal.hppreciprocal.hpp
Steps are;
$ gcc -c main.c
$ gcc -E main.c -o main.pp
Examine main.pp.
$ gcc -x cpp-output -c main.pp -o main.o
$ g++ -c reciprocal.cpp
$ g++ -c -D NDEBUG reciprocal.cpp
$ g++ -c -D NDEBUG=3 reciprocal.cpp
$ g++ -c reciprocal.cpp
Check the size of reciprocal.o.
$ g++ -c -O2 reciprocal.cpp
Compare the new size with the previous.
$ g++ -o reciprocal main.o reciprocal.o
$ ./reciprocal 7
The reciprocal of 7 is 0.142857
Link with a library say libncurses.
$ g++ -o reciprocal main.o reciprocal.o -lncurses
If it is not in your path, locate it by locate command; type
$locate libncurses
Then say it is the path; /usr/local/lib/ncurses. Give the location of this library by
% g++ -o reciprocal main.o reciprocal.o -L/usr/local/lib/ncurses -lncurses
Check the sizes and compare with the cases you compiled without library flags.
% g++ -o reciprocal reciprocal.o main.o -lncurses -static
Check the sizes and compare with the cases you compiled without static.