Thursday, January 7, 2010

Generic Makefile

Here is a Generic Makefile to compile xxx.c++ to xxx executable:
    0 CC = g++
1 CFLAG = -Wall -g -ansi
2
3 %: %.c++
4 $(CC) $(CFLAG) -o $@ $^
5
It will be very useful for all our sample codes.
For example:
hello.c++:
    0 #include <iostream>
1
2 using namespace std;
3
4 int main() {
5 cout<<"hello world"<<endl;
6 return 0;
7 }
$ make hello
g++ -Wall -g -ansi -o hello hello.c++
$ ./hello
hello world
$

1 comment:

  1. Won't it be real good if the notations are also explained.

    I mean,
    #1 - what? (e.g, CC, -Wall, -o, -g means)

    #2 - Why?(e.g, why we structured it this way)

    #3 - How?(e.g, how the same could be achieved by other means).

    hope that would help beginners like us to get more info..get different perspective...etc

    ReplyDelete