Homework 2, Compiler Flags and Make.
Short Description:
This assignment is worth 5 points.
Goals
When you finish this homework, you should:
- Understand the basics compiling programs.
- Understand compiler flags.
- Know how to use make to build a single file program.
- Understand the advantages of using compiler flags.
Formal Description
- Start a word document.
- Add you name and class identification information at the top.
- Make a new folder (directory) for this homework. Do all work in this directory.
- If you are unsure how to do this, please ask for assistance.
- Change to the new directory.
- Create a file called Makefile
- Create the file hw2a.cpp.
- In the word document, answer Question 1: What will happen when hw2a.cpp is compiled?"
- This code is legal code, and should compile unless you have introduced syntax errors.
- Provide the best answer you can, without compiling or running the code.
- Credit for this question is based on providing an answer, not on the correctness of the answer.
- Compile the code with
g++ -o hw2a hw2a.cpp
- In the word document, answer Question 2: What happened when hw2a.cpp was compiled with g++ -o hw2a hw2a.cpp.
- Make is a utility that will compile code for us based on the configuration file Makefile
- Remove the executable produced above by typing
rm hw2a
- Do not remove hw2a.cpp, or any other file, just hw2a.
- Type
make -n hw2a
- This will show the command make would execute
- But it does not execute this command.
- If it says
make: 'hw2a' is up to date.
you need to remove the executable hw2a as directed above.
- Notice that make is running g++, but with a bunch of command line flags.
- When compiling you can receive two or three different types of messages
- Syntax messages describe syntax errors.
- Syntax errors keep programs from compiling.
- I expect you are reasonably good at eliminating these.
- And they must be eliminated from all code you turn in.
- Warnings are messages that describe legal syntax that is probably used incorrectly.
- Warnings usually indicate bad code.
- And they must be eliminated from all code you turn in.
- In your word document, Question 3: Provide an example of a statement that produces a syntax error. Clearly describe what this syntax error is.
- Compile your program using make
- Type
make hw2a
- In your word document answer Question 4: What are the compiler warnings produced when using the command line flags to g++ and what do they mean?
- I received two warnings and a note.
- I expect a correct answer to this question.
- If you are unsure of the warning that involves shadowing see pages 404-408 of your book.
- What happens when you run this code?
- Remember ctrl-c (hold the control key and press c) will break out of an infinite loop.
- In your word document answer Question 5: Why does how2a.cpp execute an infinite loop and how is this related to the shadow declaration warning?
- I expect a correct answer to this question.
- Create the file hw2b.cpp containing
- Three additional make related items.
- You can build rules to perform frequent actions.
- You can add variables to Makefiles
- You can ask make to "clean" up your directory.
Required Files
A word document containing the answers to the required questions.
In addition, you may add comments, observations, or additional questions to this document.
Submission
Submit your word document to the D2L assignment folder Homework 2 by the due date.