Thursday, February 7, 2008

Building Executables on Solaris using Make


Here you can see how we can build any executable using make utility.Most people are trying to build any executable using following command:
cc -o test test.c
or
gcc -o test test.c
The above command can be simply replace using make command just fire follwing:
make test

Now see following examples :how to do the same
#cat test.c
int
main()
{
printf("inside main\n");
}


1.Using Sun's make using the defaults:

# make test
cc -o test test.c

2. Using GNU's version of make, gmake, using the defaults:

# gmake test
cc test.c -o test


Notice that in above two cases even though the arguments to cc are reversed, the end result is the same.

(Interested readers can referred to the respective manual pages for more details about make, gmake, and Makefiles.)

3. Sets the CC variable before calling make:

# CC=gcc make test
gcc -o test test.c

Notice that this time, gcc is used to compile test.c rather than cc (we can use a similar invocation with gmake if that is the build tool we want to use).

The above 3 points are also applicable to linux also.
Those who are working on Linux,can try the above make ,gmake commands.

No comments: