CMPSC 311 Test 2 Build Processing Flashcards
semantics, machines
Why do we build programs: to turn program —– from human-readable text into something —- understand
compilers, interpretors
why use language —- instead of ——-? It depends
compiling, linking, gcc, Id
there are two phases of building a program, — and —–
—– is used to build the program
—- can be used to link the program (or gcc)
gcc [options]
You will run a command to compile: ——————-
-c
—– tells the compiler to just generate object files
-Wall
—- tells the compiler to show all warnings
-g
—– tells the compiler to generate debug information
-o
— —— write output to a file
gcc hello.c -c -Wall -g -o hello.c
compiling hello.c syntax
gcc [options]
command to link sytnax: ——-
-l
—– link with a library
-g
tells the compiler to generate debug information
-o
write output to files
gcc hello.o goodbye.o -g -lmyexample -o hello
linking program syntax
library
A —— is a collection of related code and functions that are linked against a C program
exports, symbols
the library —- ——-
unresolved symbols
Your program object code has ——– ——
linker, program
the —- pulls chunks of the library. containing those symbols and places them into the ———
resolved
the program is done linking when all the pieces are —–
static
It is called —— linking because this is done at link time
statically linked, archive, linker, code
A —– —– library produces object code that is inserted into program at link time.
You are building an —- of the library which the —- uses to search for and transfer —- into your program
ar rcs lib .a
static library syntax
lib???.a
library naming: with very few exceptions all static libraries are named ———
name, file
You link against the —– of the library, not against the name of the —- in which the library exists
R
—- replace existing code with the objects passed
C
—- create the library if needed
S
—– create an index for relocatable code
dynamic library
A —– —- is a collection of related code and functions that are —- at runtime
exports, symbols
The library —– —–
unresolved symbols
Your program object code has —– ——
loader
the —- pulls chunks of the library containing those symbols and places them in the process
started, execution
The symbols are resolved when the process is —— or later during ——-
any time
it is called dynamic library, because it can be done at —– —–
execution, loadable, launch
a dynamically linked library produces object code that is inserted into program at —— time.
You are building a —- version of the library which the loader uses to —— the application
gcc -shared -o libmyexample.so a.o b.o c.o d.o
dynamic library syntax
position-independent code (PIC)
Important: all object files to be placed in library must have been compiled to —— ——- ——
predefined, memory, jumps, execution
PIC is not dependent on any being located at any —– location in ——
eg, uses relative —–, so does not matter where it is loaded at —– time
.so
Naming dynamic library with PIC is same as before?? only with —– extension ???? CHECK SLIDE 11
gcc a.c -fpic -c -Wall -g -o a.o
dynamic library PIC syntax
preprocessor, compile
The ——– processes input source code files for commands that setup the —— environment specific to that execution
#
The programmer uses —- directives to indicate what he wants that program to do. Like in —include.
there are more…
include
the —- directive tells the compiler to include data from some other data file
include “foo.h”
——- ——: this tells the compiler to look in the local (used for application programming)
include
——- —- : tells the compiler to look at the default directories and any provided by the command line
gcc -I, <>
the —— —- option:
tells the compiler to look in a specific director for include files (that are using the approach)
generally speaking, systems programming uses the —- approach to have better control over what is being included from where
define
the ——- directive allows the user to create a definition symbol that gets search/replaced throughout
constant, arrays
The #define is commonly used to define a constant that might be changed in the future eg the size of —–
undef
the —– directive undoes binding
define
—— can also be used to create simple functions called macros
macros, overheads
—— are not called as normal functions, but are replaced during preprocessing
thus no function call —— such as stack operations
if, #ifdef, #ifndef
You can conditionally compile parts of a program, using the —–, —–, and —– directives
make
the — utility is a utility for binding complex systems/program
out of date, dependencies, project files
the make utility:
figure out which parts of system are —– —- —-
figure out what the —— are between objects
issue command to create the intermediate and final —— ——
make
Note: being a good systems programmer requires mastering the —– utility
Makefile
Each system you want to build has one (or more) files defining how to build, called the ——
build, way, relate
a Makefile defines the things to —–, the —- to build them, and the way they —–
Target
Makefile:
—- a thing to build
Prerequisites
Makefile:
—– things that the target depends on
dependencies
Makefile:
—– between files eg a.o depends on a.c
variables
Makefile:
—– dat that defines elements of interest to the build
rules
Makefile:
—- are statements of targets, prerequisites and commands
rule
Also known as production, a —- defines how a particular item is built.
target: preq1, preq2, preq3..
command1
command2
(NOTE: commands must be tabbed over)
rule syntax
target, prereq(1|2|3), commands
rule syntax:
- — is the thing to be built
- —- are things needed to make the target
- — are the UNIX commands to run to make target
commands, target, prerequisites
Makefile rules:
Key idea: run the —- to build the —- when any of the noted —– are out of date
make
To run make, just type —- at the UNIX prompt.
Makefile, targets, dependency graph
running make:
It will open the —- and build any — that are out of date. thus it will look at the ——- —–.
variables
Makefile —- allow you to replace some repetitive (and changing text) with others
CC=gcc
LINK=gcc
CFLAGS=-c -Wall -I
some standard Makefile variables include
special
Make supports a range of —– variables that are used while evaluating each rule (called built-ins)
$@, $^, $
three of the most popular make built-ins
- — is the current rule target
- — is the prerequisite list
- — is the first prerequisite
builds
Built-ins are used to make —— cleaner
suffix rule
A —- —- defines a default way to generate a target from a type of prerequisites.
dependency,
suffix rule: You only need to define the —- and not the commands for those files.
types, productions
Defining suffix rule:
Step 1: define the file —– to be in suffix rules
Step 2: define the default ——-
builds
You will begin to develop a set of patterns for makefiles that you will use repeatedly over time on the different (and increasingly complex) builds. We will explore the use of these over the course of this semester.