Download presentation
Presentation is loading. Please wait.
Published byClarissa Fay Mills Modified over 9 years ago
1
Linux/g++: Maze solving in CSE326
2
Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti http://www.cs.washington.edu/lab/facilities/instr- labs.htmlhttp://www.cs.washington.edu/lab/facilities/instr- labs.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
3
Make project directory More UNIX commands are at: http://www.cs.washington.edu/education/courses/cse326/00wi/unix/unix.html
4
Look at supplied files d????????? means it’s a directory. Ignore RCS (not mentioned in project description)
5
Copy Files Oops, forgot this. Even TAs make mistakes
6
Interlude: ‘man’ Keys: q – exit man Page Up Page Down The command: apropos copy Finds all man pages that contain the word “copy” in their descriptions. Useful for finding out about a command.
7
Look at files in my dir
8
My files are read-only ‘w’ here means I can write to the files, but no-one else can
9
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 file Nic.
10
How to make runmaze (the program)
11
Test run./ is important. By default, Linux won’t search the current directory 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 will expect you to type the maze in on the keyboard – quite a hassle!
12
Run sample solution
13
Run runmaze with visualization What we type: Extra visualization window pops up (only implemented on Linux)
14
Edit runmaze.cpp – forgot & Darn, now we lost this shell until we close emacs
15
Edit runmaze.cpp Current line number
16
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 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 http://www.lns.cornell.edu/public/COMP/info/emacs/emacs_toc.html
17
Simple change to runmaze.cpp Change
18
Re-make program
19
Run re-made version
20
Intro to make – project file dependencies
21
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 of object files If runmaze doesn’t exist, or is out of date (relative to object files), here’s how to build it WARNING: this is a tab character. It has to be tab, and can’t be spaces. Those are the rules.
22
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)
23
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.o depends on runmaze.cpp + some.h files The infamous tab character strikes again! If runmaze.o doesn’t exist, or is out of date relative to the files past the colon ( : ), here’s how to build it with g++.
24
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?
25
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.cpp MazeRunner.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)
26
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 to dependencies of executable program Also, add.o file to list of files to link in (must do both) Tell make how to make Bogus.o
27
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)
28
start it/set a couple of breakpoints break gdbSquareMaze::getStartMazeNode is the form for putting a breakpoint on a C++ class method.
29
Run program in gdb To see more commands, the help command is help or look at the extra information pointers near the beginning of these slides.
30
More info 326 Computing page (more info on these tools) –http://www.cs.washington.edu/education/courses/cse326/00wi/com puting.htmlhttp://www.cs.washington.edu/education/courses/cse326/00wi/com puting.html GNU Info pages –http://www.lns.cornell.edu/public/COMP/info/http://www.lns.cornell.edu/public/COMP/info/ Friendly people in lab / other students man command osmosis
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.