Pages

Tuesday, September 11, 2012

ISU - Exercise 2


Exercise 2 Building C++ Programs for host 

Exercise 1:

In file hello.cpp:
//hello.cpp
#include<iostream>
using namespace std;
int main ()
{
cout<<"Hello World!"<<endl;
return 0;
}

In terminal:
g++ -o hello hello.cpp
./hello

Exercise 2:

File: Make file
¨















Exercise 3:

File: Make file
SOURCES=main.cpp part1.cpp part2.cpp
OBJECTS=${SOURCES:.cpp=.o}
EXECUTABLE=parts
CXX=g++

all: ${OBJECTS}
${CXX} -o ${EXECUTABLE} ${OBJECTS}

main.o: main.cpp
${CXX} -c $^

part1.o: part1.cpp part1.h
${CXX} -c $^

part2.o: part2.cpp part2.h
${CXX} -c $^

clean:
rm ${EXECUTABLE} ${OBJECTS}

help:
@echo all, clean, help

Screenshots:
Makefile

Terminal

Exercise 4:

How are the source files compiled to object files, what happens?
Make  automatically makes object (.o) files into source (.cpp) files.

Not all dependencies are handled by this approach, which?
Header (.h) files are not recognized by make, so if you change the header file make will not recompile the respective source files.

Why is this a problem?
This is a problem because the executable won't have the resent files.  











1 comment:

  1. Main goals:
    - have learned to invoke a compiler directly: ok
    - have learned how a simple makefile is structured: ok
    - have understood how to write simple makefiles for different programs: ok
    - have built and run programs that are built by direct compiler invocation and by means of make: ok
    - have understood the pros and cons for using various implicit makefile rules: not ok

    You haven't answered all exercises. The last question in the exercise document is unanswered.
    Since the point of this part is to show the level of understanding of implicit makefile rules, the goal concerning this part is not passed.

    Overall the paper looks fine.

    ReplyDelete