Basic gcc usage

This is an excerpt from the TFUG mailing list.

Date: Wed, 30 Dec 1998 20:36:13 -0700
From: murphy@U.Arizona.EDU
Subject: Re: More fun with C++

On Wed, Dec 30, 1998 at 07:42:02AM -0700, theduck wrote:
>       Well, those URLs are probably good tutorials on C/C++, but that's
> not what I need. All i'm looking for is some sort of information on using
> gcc or something similar to compile C++, some listings of the Unix
> specific includes (pthread.h, etc...), and most of all something about the
> wonder that is a.out. The man pages and such are frightfully useless...
>       Thanks for the help, though! :)

Try starting with
It will give you a few variations on the basic compiler command line.
a.out is the default executable name.  If "." isn't in your path, you
will need to run it with "./a.out".  You can change the executable
output file with the -o option.  Something like this:

g++ -g -Wall -o program

 1   2   3       4        5

1) compiler command
2) include debugging info into the executable
3) show compiler warnings
4) name the executable "program" instead of "a.out"
5) list of source files

Replace -g with -O when you do a "production" build.

If you have a lot of source files, you may want to look
into makefiles.  A makefile is similar to a project file
from the MS world.

Usually, a function/method's man page will tell you what
you must include.

Ex: socket()

$ man socket
SOCKET(2)           Linux Programmer's Manual           SOCKET(2)

       socket - create an endpoint for communication

       #include <sys/types.h>
       #include <sys/socket.h>

       int socket(int domain, int type, int protocol);

       Socket creates an endpoint for communication and returns a


If that fails, you can always grep the function out of the
header files:

$ find /usr/include -name \*.h -print | xargs grep function /dev/null

Hope this gets you started.


Tucson Free Unix Group

Additional Notes

Last updated: 12.31.98