Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji,...
-
Upload
clarissa-fay-mills -
Category
Documents
-
view
216 -
download
0
Transcript of Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji,...
![Page 1: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/1.jpg)
Linux/g++: Maze solving in CSE326
![Page 2: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/2.jpg)
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
![Page 3: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/3.jpg)
Make project directory
More UNIX commands are at: http://www.cs.washington.edu/education/courses/cse326/00wi/unix/unix.html
![Page 4: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/4.jpg)
Look at supplied files
d????????? means it’s a directory. Ignore RCS (not mentioned in projectdescription)
![Page 5: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/5.jpg)
Copy FilesOops,forgotthis.Even TAsmakemistakes
![Page 6: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/6.jpg)
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.
![Page 7: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/7.jpg)
Look at files in my dir
![Page 8: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/8.jpg)
My files are read-only‘w’ heremeans Ican write tothe files,but no-oneelse can
![Page 9: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/9.jpg)
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.
![Page 10: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/10.jpg)
How to make runmaze (the program)
![Page 11: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/11.jpg)
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!
![Page 12: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/12.jpg)
Run sample solution
![Page 13: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/13.jpg)
Run runmaze with visualization
What we type:
Extra visualizationwindow pops up(only implementedon Linux)
![Page 14: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/14.jpg)
Edit runmaze.cpp – forgot &
Darn, nowwe lost thisshell untilwe closeemacs
![Page 15: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/15.jpg)
Edit runmaze.cpp
Current line number
![Page 16: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/16.jpg)
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
![Page 17: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/17.jpg)
Simple change to runmaze.cpp
Change
![Page 18: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/18.jpg)
Re-make program
![Page 19: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/19.jpg)
Run re-made version
![Page 20: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/20.jpg)
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.
![Page 21: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/21.jpg)
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.
![Page 22: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/22.jpg)
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)
![Page 23: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/23.jpg)
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++.
![Page 24: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/24.jpg)
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?
![Page 25: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/25.jpg)
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)
![Page 26: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/26.jpg)
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
![Page 27: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/27.jpg)
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)
![Page 28: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/28.jpg)
start it/set a couple of breakpoints
break gdbSquareMaze::getStartMazeNodeis the form for putting a breakpoint on a C++ class method.
![Page 29: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/29.jpg)
Run program in gdb
To see more commands, the help command ishelpor look at the extra information pointers near the beginning of these slides.
![Page 30: Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti](https://reader034.fdocuments.in/reader034/viewer/2022051401/56649cce5503460f949990ca/html5/thumbnails/30.jpg)
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