[Courses] [C] Current topic: compiling C.

Laurel Fan laurel at sdf.lonestar.org
Mon Jul 15 12:05:38 EST 2002


colorgcc is a perl script that provides color highlighting for the
output of gcc (or g++).  To use:

1. install colorgcc.  If you have debian, an 'apt-get colorgcc' will
suffice.  There are probably rpms and such available, otherwise search
for it on google or freshmeat.

2. Set up the links.  The comments at the top of the actual script
(/usr/bin/colorgcc for me) describe how to do it.

Those instructions are pretty brief, so here are step by step
instructions:

a. Make sure you have a personal bin directory that is in the
beginning of your path[1].  Check your path by typing:
   echo $PATH
If there's a directory that looks like /home/yourusername/bin, in that
line, and the directory exists, you're good.  If not, create a bin
directory in your home directory[2]:
   cd ~; mkdir bin
Then add this directory to your path.  For zsh, I add:
   export PATH=~/bin:$PATH
to my .zprofile.  I believe that you do the same for bash (except
adding this to .bash_profile or .profile).  Now either logout and log
back in, or source the file you edited[3], then check to make sure it
worked.

b. create symbolic links.  A symbolic link from file A to file B tells
the OS that when you talk about file A, you really mean file B.  We
want to use these to tell the OS that when you talk about 'gcc', you
really mean 'colorgcc'.  The trick is that the OS also tells the
program that you run what it's original name was, so colorgcc knows
that it needs to call gcc to do the actual compiling.  To do this:
   ln -s /usr/bin/colorgcc ~/bin/gcc
   ln -s /usr/bin/colorgcc ~/bin/g++
ln is the program that creates links, -s tells it to use symbolic/soft
links.  In the first line, we are telling it to make ~/bin/gcc a
symbolic link to /usr/bin/colorgcc, so that when you run '~/bin/gcc',
colorgcc actually is run.

3. now try it out.  Write a c program (with some errors, since colored
error messages are not terribly interesting if you don't have error
messages), then compile it as normal.  You do need a color terminal
(check if your terminal is color with 'ls --color'.  Most linux
distributions will set up your console and xterms to have color).

[1] The path is where your shell looks for programs to run when you
don't give the full path to the program.  For example, if you type
'ls', it looks for an executable file called 'ls' in each of the
directories in your path.

[2] it doesn't have to be called 'bin', and it doesn't have to be in
your home directory, but this is how people usually do it.  And in
case you haven't figured it out, most shells (all that I know of)
translate ~ (tilde) to your home directory.

[3] source ~/.zprofile
    source ~/.bash_profile
    ... etc

-- 
laurel at sdf.lonestar.org
http://dreadnought.gorgorg.org



More information about the Courses mailing list