CS374: Programming Language Principles - The Compilation and Linking Processes
The goals of this activity are:
- To describe the compilation process
- To define an algorithm to resolve linker dependencies using a multi-pass approach
- To define possible outcomes of the compilation process, including assembly code, machine code, and intermediate bytecode
- To describe the role of external libraries in extending the functionality of a programming language and the mechanisms for integrating them
Feel free to visit these resources for supplemental background reading material.
Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.
Model 1: Linker Processes
- Assume that we compile with
gcc file1.c file2.c. What does the compiler have to do with the variable
file1.c, since it does not yet know here the variable is declared?
- With what is the variable
x updated in
file1.c once it can resolve it to
int x in
- What does the assignment in
a() do to the variable in
- What if there was a variable in
- What would happen if the variable
file1.c was also initialized to a value when it was first declared?
- Under what circumstances do you think a variable is bound to a global, versus a linker error?
- In the C language, what do you think the
static keyword does? How can we use this to protect global variables inside externally linked library functions?
I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.