The programming language C and its close relative C++ are very popular programming languages today. The language C was originally at Bell laboratories in the earlier 70s the aim of C's original design was to blend the power and control of a language that is .close to the hardware. while still facilitating higher level machine independent programming. [1] Bjarne Stroustrup (Professor and holder of the College of Engineering Chair in Computer Science at Texas A&M University!) developed the C++ programming language to provide stronger type checking and support a "wider range of programming styles" such as object oriented programming. C++ is commonly referred to as "a better C" in that most C programs will compile as C++ programs but C++ allows you extra freedoms and more tools to use in your programming. [2]
Here at the Computer Science department we use the "GNU
Compiler Collection" (commonly referred to just as GCC) which is a
widely popular open source compiler. As of Fall 2003 the current version being
used at the department is 3.3. For compileing C code use the gcc command,
when compiling C++ code use the g++ command.
In all the examples below I use .c or .cpp extensions;
however GCC will recognize a wide Varity of C or C++ file extensions. You may
use the following with GCC:
<source file>.cc
<source file>.cp
<source file>.cxx
<source file>.cpp
<source file>.c++
<source file>.C
Also in the later steps an individual file may be compiled to object code which
will have .o extension.
#include <stdio.h>
|
#include <iostream>
|
> gcc <your source file>.c -o <your executable binary file>
Or use the following for C++ code:
> g++ <your source file>.cpp -o <your executable binary file>
> ./<your executable binary file>
|
Fig 01: Compiling with plain C |
Fig 02: Compiling with C++ |
When compiling programs that span multiple source files (I will use source file and component interchangeable) with gcc you have two options. You can compile all the components and then link them together in one step or you can split the compilation into several steps. The advantages of the first option is that it is simple, easy to understand and use however as your programs grow you will find that sometimes it takes the compiler longer and longer to compile it each time. This is because gcc has to recompile the entire program each time you make a change in one small area. To address this problem you can compile each component separately, then when you change one component just recompile that individual component and link it together with the other previously compiled components to create an executable binary.
> .gcc <component1>.c <component2>.c -o <your program>
Or the same for C++:
> g++ <component1>.cpp <component2>.cpp -o <your program>
The above command will compile both components one and two, then link them together and store the resulting executable binary to disk. Note, you are not limited to only two source files you may include as many as you one in one command.
> gcc .c <component1>.c
> gcc .c <component2>.c
> gcc <component1>.o <component2>.o -o <your program>
Or the same for C++:
> g++ -c <component1>.cpp
> g++ -c <component2>.cpp
> g++ <component1>.o <component2>.o -o <your program>
The above commands will compile each component separately and store the binary
in a
[1] Dennis M. Ritchie. "The Development of the C Language" accessed on
11/20/2003, http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
[2] Bjarne Stroustrup. "Byarne Stroustrup's Homepage" accessed on 11/20/2003,
http://www.research.att.com/~bs/homepage.html specifically the FAQ
section.
Monday - Friday:
7 am - Midnight
Saturday:
10 am - 7 pm
Sunday:
12 pm - Midnight
Hours subject to change during holidays, emergencies, and summer semester.