16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Development Tools<br />

$ cc –o pgm main.a filel.o file2.o<br />

cc [options] file.c<br />

-C compile only (suppress link editor)<br />

-g generate code for debugger<br />

-O optimize for speed<br />

-p produce code for profiler<br />

-o name put executable code in name<br />

-M make a makefile<br />

-S generate assembler code .s file<br />

- ld – link editor<br />

Takes one or object files or libraries as input and combines <strong>the</strong>m to produce executable file. It resolves references<br />

to external symbols, and performs "relocation" of addresses.<br />

-lx<br />

search library libx.a<br />

-L dir directory o<strong>the</strong>r than /lib or /usr/lib<br />

-u symname enter undefined symbol in symbol table<br />

-S strip symbol table<br />

- cpp -c preprocessor<br />

-Dname=def define name for preprocessor<br />

-Idir<br />

include file directory<br />

-E invoke preprocessor only<br />

Example:<br />

# Example makefile<br />

LIB=~/lib<br />

CFLAGS=-I~/include -DDEBUG<br />

.c.o:<br />

cc -c $(CFLAGS) $<<br />

main: main.a filel.o file2.o<br />

$(CC) -o main filel.o file2.o -L $(LIB)<br />

C Preprocessor<br />

cpp<br />

- actions before c compiler<br />

#define ident token e.g. #define IF if(<br />

#undef ident #define THEN )<br />

#define BEGIN{<br />

#include "filename" #define END }<br />

#include #define ELSE else<br />

used to include:<br />

#defines<br />

externs<br />

typedefs<br />

struct definitions<br />

nested #includes<br />

#if const_expr<br />

#ifdef ident<br />

#ifndef ident<br />

#else<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!