Introduction

General Information

Login in to Linux machines

If there is a problem, go to desk in 1005 for assistance

Communication Protocol

EECS 268 website will be updated with assignments / reference material / announcements.

Email for important information will be sent to class-registered email address

Linux Tools

Text-editors

g++

GNU project c++ compiler.

Used to compile programs into object files & link object files together for an executable.
(object file is a processed version of source code file. Has to contain Machine code, might contain other info i.e. for debuggers.)

g++ Examples:

Compile to object file:
g++ -c HelloWorld.cpp >> HelloWorld.o

Link object files together:
g++ HelloWorld.o MyClass.o -o executable >> executable

Make

Tool for automatically building large (or small) applications.

Usually used with C or C++ programs, but could be used for any language

Basic Makefile:

Assume we have 3 files: MyClass.h, MyClass.cpp, and HelloWorld.cpp.
Assume HelloWorld.cpp depends on MyClass.h
We would like to create an application with the name “lab1”.

makefile:

  
    lab1:HelloWorld.o MyClass.o
      g++ HelloWorld.o MyClass.o -o lab1
    HelloWorld.o:HelloWorld.cpp MyClass.h
      g++ -c HelloWorld.cpp
    MyClass.o:MyClass.h MyClass.cpp
      g++ -c MyClass.cpp
    clean:
      rm -f *.o *~ lab1
  

sample makefile

Makefile explanation

Each pair in the makefile is considered a Make Rule. Make rules are composed in the following manner:

target:prerequisites

tab commands

Make starts at the first target and looks to see if its prerequisites have any commands associated with them. Make continues down the chain until it reaches a target with no prerequisites or one whose prerequisites have no associated rules. Also through this process, it checks to see if each target is up-to-date, that is, if their have been modifications to the files associated with a particular target.

In the example above, make would start with the lab1 target and then move to the HelloWorld.o and MyClass.o targets. Both of these targets have prerequisites with no rules associated with them. Running make or make lab1 would first cause the HelloWorld.o and MyClass.o object files to be generated from the commands associated with these targets. Then the lab1 executable would be compiled from those object files using the g++ HelloWorld.o MyClass.o -o lab1 command.

clean is a target in this make file with no prerequisites. Running make clean would remove all files ending with “.o” and “~” as well as the lab1 executable.

Note: The command line for each make rule needs to start with a tab character.

Debugging

Symbolic debuggers allow for the examination of the internal workings of a program during its execution. From the gdb man page: “The purpose of a debugger is to allow you to see what is going on ‘inside’ another program while it executes.” gdb is the GNU debugger, a command-line debugging utility that provides all the common functionality of a debugger. Debuggers allow you to look at the internals of a program in many ways including:

ddd or Data Display Debugger is a front-end to gdb which provides a graphical user interface for debugging with gdb.

Note: In order to use gdb (and therefore ddd), all components of a program must be compiled using the “-g” flag.

Sample Program to Debug

Common Commands in ddd

Tar file generation

Projects containing more than one file should be packaged together as a tar file for submission.

Sample tar command:
tar cf jvalland_project1.tar jvalland_project1

Explanation:

This would be called from the parent directory of the project. So if the project was at ~/eecs268/project1/ you would execute this command from ~/eecs268/.

Note: Name the folder you are tarring uniquely, as well as the generated tar file itself.

Flags:

Extracting a tar file:
tar xf project1.tar

Flag:

Note: The submitted tar file for labs and projects should contain your first / last name as well as an indication as to which project / lab is being submitted.

Example:
jvalland_lab01.tar

Other useful commands

Other Information and Tips

All lab submissions must compile and run on linux lab machines. Be careful using Windows-based text-editors as invisible characters can differ causing unusual and difficult to debug errors.