240 likes | 273 Views
CSE 326. TA: Maya Rodrig Our C++ guru: Nic Bone. Linux machines at UW. Machine Names: Ceylon, Sumatra, Fiji, Tahiti http://www.cs.washington.edu/lab/facilities/instr-labs.html Access Use X-terminals in back of Sieg 329 (click on one of the Linux machines) Use Windows machines.
E N D
CSE 326 TA: Maya Rodrig Our C++ guru: Nic Bone
Linux machines at UW • Machine Names: Ceylon, Sumatra, Fiji, Tahiti • http://www.cs.washington.edu/lab/facilities/instr-labs.html • Access • Use X-terminals in back of Sieg 329 (click on one of the Linux machines) • Use Windows machines
Opening an XTERM on a Windows machine • Log into the CSEPCLAB domain • Start -> Programs -> Reflection -> Reflection X • “X Client Manager” should open • Select the “linux.rxc” connection template • Select the KERBERIZED TELNET method • Enter the host name (fiji, ceylon, tahiti, sumatra) • Click Connect • An XTERM should open (if not, ask for help)
Unix Manual: ‘man’ The command: apropos copy Finds all man pages that contain the word “copy” in their descriptions. Useful for finding out about a command. Keys: q – exit man Page Up Page Down
Make Project Directory fiji% mkdir cse326 fiji% cd cse326 fiji% mkdir proj1 fiji% cd proj1 fiji% pwd /homes/iws/rodrig/cse326/proj1 fiji% ls /homes/iws/rodrig/cse326/proj1 fiji% More UNIX commands are at: http://www.cs.washington.edu/education/courses/cse326/00wi/unix/unix.html
File Permissions ‘w’ here means I can write to the files, but no-one else 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 file Nic.
How to run your program ./ 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, the program will expect you to type the input on the keyboard – quite a hassle!
Edit runmaze.cpp – forgot & Darn, now we lost this shell until we close emacs
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
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.
g++ linking command line • -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) g++ -o runmaze -g runmaze.o MazeRunner.o RandomMazeRunner.o Maze.o SquareMaze.o VisualizeSquareMazeRunner.o GPKernel.o -L/usr/X11R6/lib -lX11
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++.
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 the .h file to every .o file of a .cpp file that #includes the .h file, 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)
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
Debugging Recommendations: • 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 (make sure debugging is off before turning in your project). • Use gdb (see below) • Use xxgdb (has dinky graphical user interface)
start it/set a couple of breakpoints break gdbSquareMaze::getStartMazeNode is the form for putting a breakpoint on a C++ class method.
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.
More info • 326 Computing page (more info on these tools) • http://www.cs.washington.edu/education/courses/cse326/00wi/computing.html • GNU Info pages • http://www.lns.cornell.edu/public/COMP/info/ • Friendly people in lab / other students • man command