Sams Teach Yourself C++ in 21 Days

(singke) #1
Getting Started 15

1


The Process of Creating the Program ....................................................................


The first step in creating a new program is to write the appropriate commands (state-
ments) into a source file. Although the source code in your file is somewhat cryptic, and
anyone who doesn’t know C++ will struggle to understand what it is for, it is still in
what we call human-readable form. Your source code file is not a program and it can’t be
executed, or run, as an executable program file can.

Creating an Object File with the Compiler ......................................................


To turn your source code into a program, you use a compiler. How you invoke your com-
piler and how you tell it where to find your source code varies from compiler to com-
piler; check your documentation.
After your source code is compiled, an object file is produced. This file is often named
with the extension .objor .o. This is still not an executable program, however. To turn
this into an executable program, you must run your linker.

Creating an Executable File with the Linker ..................................................


C++ programs are typically created by linking one or more object files (.objor .ofiles)
with one or more libraries. A library is a collection of linkable files that were supplied with
your compiler, that you purchased separately, or that you created and compiled. All C++
compilers come with a library of useful functions and classes that you can include in your
program. You’ll learn more about functions and classes in great detail in the next few days.
The steps to create an executable file are


  1. Create a source code file with a .cppextension.

  2. Compile the source code into an object file with the .objor .oextension.

  3. Link your object file with any needed libraries to produce an executable program.


DOuse a simple text editor to create
your source code, or use the built-in edi-
tor that comes with your compiler.
DOsave your files with the .c, .cp, or
.cppextension. The .cppextension is
recommended.
DOcheck your documentation for
specifics about your compiler and linker
to ensure that you know how to compile
and link your programs.

DON’Tuse a word processor that saves
special formatting characters. If you do
use a word processor, save the file as
ASCII text.
DON’Tuse a .cextension if your com-
piler treats such files as C code instead of
C++ code.

DO DON’T

Free download pdf