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 1Learning Unix and C
Software Project – Winter 2007 / 2008
Trang 2Administration
Trang 4The goals of the course
Learn C
Learn (a bit) Unix
Practice software development:
Understanding software requirements
Trang 5Course 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 6Overview (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 77Introduction to UNIX
(and Linux…)
Trang 8 provides programmers and users with an
interface to access those resources.
multi-users, GUI, security, etc.
Trang 9Thompson & 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 10Basic 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 11Additional 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 12File 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 13Editing text files in Unix
Common text editors:
pico - simple but very basic, similar to
Trang 14Pipes 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 15Comparing 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 16Development environments for C
Trang 18C programming process
Hello.c Edit Compile Hello.o Link Hello
Executable Output
Trang 1919Basic tools in UNIX
Trang 20Compiling 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 21Make 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 22gdb – the GNU debugger
Running gdb: gdb <exe>
Useful commands: help, quit, n, s,
b <function>/<#line>
Trang 2323Eclipse
Trang 24(Linux)
Including C/C++ projects
Code requires porting to LINUX
Relatively complicated installation
Trang 25Create a new workspace
/a/home/cc/students/cs/ozery/soft-proj08
Trang 26Create a new project-1 (Linux lab)
Trang 27Create a new project -2 (Linux Lab)
Trang 28create a new project (windows)
Trang 29Add source file
Trang 30Add makefile (a file named “makefile”)
Trang 32Project properties (windows)
Trang 33Build the project
Trang 34Running 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 35Debugging under Windows+cygwin
Console in a new window
Trang 36Microsoft Visual Studio
Trang 37Advantages / 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 38Creating a project (and a solution)
Trang 39Adding new source files
Right click on project name: Add->New Item
Write file name, including the c suffix (e.g file.c)
Trang 40Build project
Trang 41Compiling with debug information
Trang 42Removing optimization
Trang 43Linking with debug information
Trang 44Debugging
Trang 4545Submission 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 48Grading 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).