1. Trang chủ
  2. » Công Nghệ Thông Tin

Learning unix and C slide

49 189 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 49
Dung lượng 1,1 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Course grade  Final grade is based on:  Exam  Assignments and final project:  “Black box” tests: automatic tests that run the program and check its output  “White box” tests: code r

Trang 1

Learning Unix and C

Software Project – Winter 2007 / 2008

Trang 2

Administration

Trang 4

The goals of the course

Learn C

Learn (a bit) Unix

Practice software development:

Understanding software requirements

Trang 5

Course grade

Final grade is based on:

Exam

Assignments and final project:

 “Black box” tests: automatic tests that run the program and check its output

 “White box” tests: code review

Trang 6

Overview (for the rest of this lesson)

Introduction to Unix

Development environments for C

Basic tools in UNIX

Eclipse

Visual Studio

Submission of assignments and project

Trang 7

7Introduction to UNIX

(and Linux…)

Trang 8

provides programmers and users with an

interface to access those resources.

multi-users, GUI, security, etc.

Trang 9

Thompson & Ritchie at AT&T Bell Labs.

70’s – Rewritten in C (enables portability).

80’s – System-V (AT&T) and BSD (Berkeley) versions.

90’s – Linux by Linus Torvalds.

For basic introduction and commands

see course web-page ( unix.doc )

Trang 10

Basic commands in Unix shells

Command Short explanation

ls -l prints the content of a directory

pwd prints the name of the current

rm removes (deletes) a file

rmdir removes an empty directory

man help (manual) on a command

Trang 11

Additional Unix commands

cat – concatenate files and print to standard

output

cat file1

cat file1 file2 file3

less – file viewer (“less” is better than “more”)

which – locate a command

groups – prints the groups the user in

(permission )

grep – prints lines matching to a pattern

grep –i “.*lib.*” foo.bar

find – search for a file in a directory

find –name “*.txt” –print

find ~/ –name “*.o” -exec rm {} \;

clear – clears the terminal screen

finger – prints information about a user

who – shows who is logged in

whoami – identifies the current user

Trang 12

File and directory permissions in Unix

permissions = bits 2-10 (bit 1: “d”=directory, “-” =

file)

bit 1 = whether is a directory (d) or not (-)

bits 2-4: owner permissions

bits 5-7: group permissions

bits 8-10: other permissions

rwx:

r – read permission

w – write permission

x – execute (file)/ can cd (directory)

changing permissions: chmod

chmod go+rx a.out

chmod –R 755 mydir

group permissions

Trang 13

Editing text files in Unix

Common text editors:

pico - simple but very basic, similar to

Trang 14

Pipes and redirections to/from files

Pipe: prog1 | prog2 – the output of

prog1 is redirected to the input of prog2

Example: ls –l | less

Output redirection to file

prog > foo.out :may cause an error if foo.out exists

prog >! foo.out :truncates foo.out if exists

prog >> foo.out :may cause error if foo.out does NOT exist

prog >>! foo.out :does not check whether

foo.out exists

Input redirection (read from file)

prog < foo.in

Trang 15

Comparing files (program tests)

prog <1.in >! my1.out : reading from

1.in and writing to 1.out

diff my1.out 1.out –compares files line

by line

Ignoring all whitespaces:

diff –w my1.out 1.out

Trang 16

Development environments for C

Trang 18

C programming process

Hello.c Edit Compile Hello.o Link Hello

Executable Output

Trang 19

19Basic tools in UNIX

Trang 20

Compiling and linking

Compiling and linking

gcc hello.c –o hello

Only compiling (creating hello.o)

gcc –c hello.c

Only linking

gcc hello.o –o hello

Additional common flags to gcc:

-g – allows debugging

-l<library-name> - linking with external

libraries

Trang 21

Make and makefiles (in short)

makefile: a collection of rules to make targets

make: a utility that “executes” makefiles

-rm hello.o hello hello: hello.o

gcc -g hello.o -o hello hello.o: hello.c

gcc -c -g hello.c

rule

target name dependencies

command

Trang 22

gdb – the GNU debugger

Running gdb: gdb <exe>

Useful commands: help, quit, n, s,

b <function>/<#line>

Trang 23

23Eclipse

Trang 24

(Linux)

Including C/C++ projects

Code requires porting to LINUX

Relatively complicated installation

Trang 25

Create a new workspace

/a/home/cc/students/cs/ozery/soft-proj08

Trang 26

Create a new project-1 (Linux lab)

Trang 27

Create a new project -2 (Linux Lab)

Trang 28

create a new project (windows)

Trang 29

Add source file

Trang 30

Add makefile (a file named “makefile”)

Trang 32

Project properties (windows)

Trang 33

Build the project

Trang 34

Running and Debugging (LINUX lab)

Right click on the executable file (with the bug icon ):

Run As->Local C/C++ Application

Debug As->Local C/C++ Application

Set debugger to “GDB Debugger”

Trang 35

Debugging under Windows+cygwin

Console in a new window

Trang 36

Microsoft Visual Studio

Trang 37

Advantages / disadvantage, download info

Advantages:

A common and friendly IDE for C/C++.

Recommended for development under Windows

A relatively simple installation, good support in the internet

Disadvantage: requires porting to Linux

Downloads:

Visual Studio Express C++ (2005 edition)

(see http://msdn2.microsoft.com/visualc/)

Free download (2003 edition) at CS School

“burning station” (see FAQ)

Available in the CS School Linux Lab – via

nt-nlb application Requires Windows account.

Trang 38

Creating a project (and a solution)

Trang 39

Adding new source files

Right click on project name: Add->New Item

Write file name, including the c suffix (e.g file.c)

Trang 40

Build project

Trang 41

Compiling with debug information

Trang 42

Removing optimization

Trang 43

Linking with debug information

Trang 44

Debugging

Trang 45

45Submission of assignments

and project

Trang 46

The submitted directories of the two

partners should be identical!

Trang 47

Perform rebuild: make clean + make all

Verify correct run: use given input/outfile + diff.

Output should be exactly as specified! (do not add unnecessary friendly “printf” commands!)

Before submission – give permission

submitted to the checker’s mail-box (details

will be given later)

Trang 48

Grading policy

 If you do not follow the submission

guidelines and your exercise cannot

Trang 49

a detailed description of your appeal

the original printout (with the checker’s comments).

Ngày đăng: 24/10/2014, 10:53

TỪ KHÓA LIÊN QUAN