Upload
clarissa-fay-mills
View
218
Download
0
Tags:
Embed Size (px)
Citation preview
Linux/g++: Maze solving in CSE326
Linux machines at U. W.
• Machine Names: Ceylon, Sumatra, Fiji, Tahiti• http://www.cs.washington.edu/lab/facilities/instr-l
abs.html• Access
– Use X-terminals in back of Sieg 329 (click on one of the linux machine names)
– Use Windows machine, ask someone in lab for help
Make project directory
More UNIX commands are at: http://www.cs.washington.edu/education/courses/cse326/00wi/unix/unix.html
Look at supplied files
d????????? means it’s a directory. Ignore RCS (not mentioned in projectdescription)
Copy FilesOops,forgotthis.Even TAsmakemistakes
Interlude: ‘man’
Keys:q – exit manPage UpPage Down
The command:apropos copyFinds all man pages that containthe word “copy” in theirdescriptions. Useful for findingout about a command.
Look at files in my dir
My files are read-only‘w’ heremeans Ican write tothe files,but no-oneelse can
chmod (thanks to Nic Bone)> I'm having trouble understanding the man files. How would I change permission to> -rwxr--r--> > What's the syntax?The easy-to-remember way to do this is to type:% chmod a+r file% chmod u+wx file% chmod go-wx file
Meaning of the symbols:r: read w: write x: execute u: user g: group o: other a: all three (u, g, and o)+: add this permission-: remove this permission
You can also set the permissions with one command using a numeric code of three numbers in the range 0-7. The first number corresponds to user permissions, the second to group permissions, and the third to other (or world) permissions. Read permission is +4, write permission is +2, and execute permission is +1. So to change permission to -rwxr--r--, we would type:% chmod 744 fileNic.
How to make runmaze (the program)
Test run
./ is important. By default, Linux won’t search the currentdirectory for a program. So you have to explicitly tell it(eventually, you can change your PATH environment variable)
< means get the input from the file to the right (inputs/maze1.txt), instead of the keyboard. If you don’t put this in, runmaze willexpect you to type the maze in on the keyboard – quite a hassle!
Run sample solution
Run runmaze with visualization
What we type:
Extra visualizationwindow pops up(only implementedon Linux)
Edit runmaze.cpp – forgot &
Darn, nowwe lost thisshell untilwe closeemacs
Edit runmaze.cpp
Current line number
Emacs keys
• CTRL-X S (hold down control for both letters)– Save your work
• CTRL-X C– Exit emacs
• CTRL-G– Abort current command (if you accidentally typed something wrong)
• More:– (Quick intro)
http://www.cs.washington.edu/education/courses/cse326/00wi/unix/emacs.html
– (official documentation) http://www.lns.cornell.edu/public/COMP/info/emacs/emacs_toc.html
Simple change to runmaze.cpp
Change
Re-make program
Run re-made version
Intro to make – project file dependencies
runm aze
runm aze.oM aze.o
SquareM aze.oO ther
object files
runm aze.cpp
M aze.cppSquareM aze.cpp
O ther .h,.cpp files
M aze.h
SquareM aze.h
BTW : This is a graph, and m ake w ill perform a "TopologicalSort" to figure out in what order to build the files.
2 lines from Makefile
runmaze : runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o
g++ -o runmaze -g runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o -L/usr/X11R6/lib -lX11
runmaze (executable file) is dependant on a bunch ofobject files
If runmaze doesn’t exist, oris out of date (relative toobject files), here’s how tobuild it
WARNING: this is a tabcharacter. It has to be tab,and can’t be spaces. Thoseare the rules.
g++ linking command line
g++ -o runmaze -g runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o -L/usr/X11R6/lib -lX11
• -o runmaze– Call the output file ‘runmaze’ (instead of a.out, which is the
default)
• -g– Include debugging information, so you can use a debugger
• -L/usr/X11R6/lib -lX11– Include X-Windows libraries (for visualization part)
2 lines for runmaze.cpp (well, technically runmaze.o)
runmaze.o : runmaze.cpp Maze.h SquareMaze.h MazeRunner.h RandomMazeRunner.h VisualizeSquareMazeRunner.h
g++ -Wall -c -g runmaze.cpp
The object file runmaze.odepends on runmaze.cpp +some .h files
The infamous tabcharacter strikesagain!
If runmaze.o doesn’t exist, or is out of daterelative to the files past the colon ( : ), here’show to build it with g++.
g++ compiling flags
• -c– Only compile, don’t link – we’ll let make decide when to link.
• -Wall– g++ will give us all of the Warnings it can think of. Maybe it’ll
help us find a bug quickly.
• -g– Add debugging information.
Is this the g as in –g? Who knows?
So you want to add a .h file• Add it to every .o/.cpp that #includes it, directly or
indirectly.
runmaze.o : runmaze.cpp Maze.h SquareMaze.h MazeRunner.h RandomMazeRunner.h VisualizeSquareMazeRunner.h Fictitious.h
g++ -Wall -c -g runmaze.cppMazeRunner.o : MazeRunner.cpp Maze.h MazeRunner.h Fictitious.h
g++ -Wall -c -g MazeRunner.cpp
RandomMazeRunner.o : RandomMazeRunner.cpp Maze.h MazeRunner.h RandomMazeRunner.h
g++ -Wall -c -g RandomMazeRunner.cpp
But RandomMazeRunner.cpp doesn’t #include Fictitious.h(in our example)
Adding a .cpp file
runmaze : runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o Bogus.o
g++ -o runmaze -g runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o Bogus.o -L/usr/X11R6/lib -lX11
Bogus.o : Bogus.cpp Bogus.h Maze.h MazeRunner.h
g++ -Wall -c -g Bogus.cpp
Add .o file todependencies ofexecutable program
Also, add .o file tolist of files to linkin (must do both)
Tell make how tomake Bogus.o
Debugging
• Zasha recommends: – add print statements (or cout<<) so you can see what your
program is doing.
– Make them check a global variable (doDebug), so you can turn them off & on (to turnin for grading)
– Learn debugger later.
• Or – use gdb (see below)
– use xxgdb (has dinky graphical user interface)
start it/set a couple of breakpoints
break gdbSquareMaze::getStartMazeNodeis the form for putting a breakpoint on a C++ class method.
Run program in gdb
To see more commands, the help command ishelpor look at the extra information pointers near the beginning of these slides.
More info
• 326 Computing page (more info on these tools)– http://www.cs.washington.edu/education/courses/cse326/00wi/co
mputing.html
• GNU Info pages– http://www.lns.cornell.edu/public/COMP/info/
• Friendly people in lab / other students
• man command
• osmosis