End Presentation


TWiki Slide Show
Next
Development Tools: Editor, Compiler, Linker, Debugger, Make

Uli Raich

First Semester 2017/2018

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 27





















TWiki Slide Show
Next
The development cycle
The first and most important part in the development cycle is that you think!

Of course a hello world program you can start implementing immediately.

This however is not the case for real world problems.

Break down the problem into small manageable parts that you can

implement and test individually

Think about how these smaller pieces will be interfaced with each other

to create the full program

Make a design on paper or use one of the software design tools.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 27





















TWiki Slide Show
Next
The editor
There are plenty of editors on Linux:
  • vi: the first and traditional full screen editor
    this one is for die-hard Unix gurus but on some very small
    Unix system it is the only editor installed
  • emacs: another traditional Unix editor
    (and my favorite, probably because I know it best).
    The advantage of using emacs is that the key sequences used
    for editing are also understood by bash. This is also the favorite of many programmers.
    People say it can do everything except making coffee.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 27





















TWiki Slide Show
Next
More Editors
  • gedit: the editor that comes with the Gnome desktop
  • joe, jed, nano, ed …
In addition to these we have editors being part of

Integrated Development Environments (IDEs)

  • eclipse: originally developed for Java but has “perspectives” for other languages like C, C++
  • qtcreator: an IDE tailored to development of window based Qt programs. Mainly C++
  • netbeans: tailored to Java but can also do C/C++

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 27





















TWiki Slide Show
Next
Linking several object files
We have seen that functions can be implemented in dedicated files.

In our calculator, each operation can be implemented

in a separate function on a separate file.

We then have to compile 5 C programs to object files and

finally link these into the final executable.

The C library is automatically linked as well but we may also

need to link additional libraries (e.g. libm.so the math library).

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 27





















TWiki Slide Show
Next
emacs
emacs is written in lisp. It has so many functionalities

that I have no chance to show all during the lectures.

I will give a little demo but you will not be able to remember

all the key sequences even until this afternoon for the exercises

However, many functions are accessible through pull-down

menus and the key sequences are given

Emacs has an online tutorial, which you should have a look at.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 27





















TWiki Slide Show
Next
emacs example
emacs when editing "hello world"

emacs-1.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 27





















TWiki Slide Show
Next
A more elaborated emacs session
emacs-2.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 27





















TWiki Slide Show
Next
Demo on emacs

!!! Interruption !!!

You want to know how to really use emacs to its full potential?

Get the manual (some 635 pages!)

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 27





















TWiki Slide Show
Next
gcc
gcc is the de facto industry standard C compiler

It exists for many different machines

  • Intel processors
  • ARM MIPS
  • And it comes as native or as cross compiler
gcc is open source and you can have a look how to implement such a compiler,

and you can compile the latest version of it yourself

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 27





















TWiki Slide Show
Next
gcc components
gcc has several components:

  • The preprocessor
    this treats the #define and #include statements to
    build a complete C source file for the compiler
  • The C compiler proper
  • The assembler
  • The Linker

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 27





















TWiki Slide Show
Next
gcc options
gcc has plenty of options which may also depend on the compiler version.

gcc for ARM has different options from gcc for Intel.

Here are just a few of them:

  • -Wall
    don’t ignore any warnings. You may however also specify which
    type of warnings you are interested in
  • -g keep symbol table for debugging
  • -E only run the preprocessor
  • -S create assembly code and stop
  • -c compile into object code, don't link

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 27





















TWiki Slide Show
Next
gcc input and output
Gcc input can be any of the following:

  • C source code: myCode.c
  • Assembly code: myCode.s
  • Object code: myCode.o
  • Libraries: libmylibrary.a or libmylibrary.so
If you do not specify the name of the output file (-o option) the executable will be called a.out

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 27





















TWiki Slide Show
Next
make
We have seen that quite a few gcc commands may be needed

even if we only build a ridiculously small program as our calculator

What about a program with thousands of source files?

We need a tool with which we can describe how to build the program

and which will execute all necessary steps automatically:

make

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 27





















TWiki Slide Show
Next
The Makefile
Traditionally the description is called Makefile

(with capital M) even though any other name will do as well

The Makefile contains

  • Macros (similar to Variables)
  • Dependencies
  • targets

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 27





















TWiki Slide Show
Next
An example Makefile
helloMakefile.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 27





















TWiki Slide Show
Next
Targets and dependencies
The target is the thing that is to be done in this step:

hello: hello.c hello.h

In this case hello is the target and it depends on

hello.c and hello.h

Then you have the action needed to create the target

which has a tab character (invisible!) before the text:

Tab $(CC) $(CFLAGS) -o hello hello.c

This will compile and link output the hello executable

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 27





















TWiki Slide Show
Next
A simpler Makefile
Make has predefined rules and it knows hot to produce

a .o file from a .c file

We can therefore restrict out Makefile to this:

simpleMakefile.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 18 of 27





















TWiki Slide Show
Next
Special macros
  • CC is the C compiler, it defaults to cc
  • CFLAGS are the flags to be passed to the C compiler
  • LDFLAGS are the flags to be passed to the linker
  • LDLIBS are the libraries to be linked into the executable
  • RM translates into rm -f
  • $< is the file that caused the action
  • $* is the prefix shared by target and dependent file
  • $@ is the file to be made
  • $? are the dependent files that have changed
  • $^ are all dependent files

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 19 of 27





















TWiki Slide Show
Next
more Makefile examples
%.o: %.c:

$(CC) $(CFLAGS) -c $<

Or

$(CC) $(CFLAGS) -c $*.c

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 20 of 27





















TWiki Slide Show
Next
Makefile with several object files to be linked
complexMakefile.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 21 of 27





















TWiki Slide Show
Next
Makefile improved
improvedMakefile.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 22 of 27





















TWiki Slide Show
Next
know more about make?
You want to know more about make?

There are several tutorials on the WEB

There is also the official manual which is a

200 pages book!

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 23 of 27





















TWiki Slide Show
Next
Running the program
To run the program we have to run ./nameOfBinary

Why do you have ./ before the program name and what does it mean?

Is there a means to run the program without the ./ ?

Beginner programmers often think that the job is done once the

program is compiled and all the syntax errors fixed.

The truth is that then the work has just justed.

Often there are programming errors (bugs) in the logic and

the program mis-behaves.

How do we spot these errors?

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 24 of 27





















TWiki Slide Show
Next
Printing debug information
Very often programmers put print statements purely for the sake of debugging.

This is annoying when running the final program

where this information should not be needed any more.

One easy way out of the dilemma is given by the C preprocessor:

#define DEBUG 1

#ifdef DEBUG

p rintf(“printing some variable contents %d\n”,variable);

#endif

Commenting out the #define statement will get rid of all debugging prints.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 25 of 27





















TWiki Slide Show
Next
The debugger gdb
Sometimes printing debug information is not enough

and we have to use a debugger.

gdb the GNU debugger is still the standard tool

Compile your program with the -g option to retain the symbol table

Then run the program within the debugger

gdb yourProgram

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 26 of 27





















TWiki Slide Show
Next
Using gdb
  • break: set a breakpoint to stop running when arriving at this point
  • run: start the program
  • continue: continue running after a breakpoint
  • next: execute the program line next line
  • step: step into the function if the next line is a function call
  • list: print the source code at the current position in the program
  • bt: backtrace, show the program stack
  • print: print a variable
For more information read the manual.

This is rather short (a bit more than 800 pages)

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 27 of 27





















First slide Previous End Presentation






























-- Uli Raich - 2017-09-08

Comments

I Attachment History Action Size Date Who Comment
PNGpng complexMakefile.png r1 manage 27.5 K 2017-09-11 - 12:26 UnknownUser  
PNGpng emacs-1.png r1 manage 34.1 K 2017-09-11 - 11:27 UnknownUser  
PNGpng emacs-2.png r1 manage 299.7 K 2017-09-11 - 11:27 UnknownUser  
PNGpng helloMakefile.png r1 manage 16.4 K 2017-09-11 - 11:42 UnknownUser  
PNGpng improvedMakefile.png r1 manage 38.3 K 2017-09-11 - 11:42 UnknownUser  
Unknown file formatodp lecture_4.odp r1 manage 447.3 K 2017-10-16 - 12:40 UnknownUser  
Unknown file formatgz makeExamples.tar.gz r1 manage 1.7 K 2017-10-16 - 18:44 UnknownUser  
PNGpng simpleMakefile.png r1 manage 6.6 K 2017-09-11 - 11:48 UnknownUser  

This topic: Embedded_Systems > WebHome > LectureSlides > Lecture4:DevelopmentTools
Topic revision: r6 - 2018-10-04 - IsaacArmahMensah
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback