Presentation is loading. Please wait.

Presentation is loading. Please wait.

TA: Maya Rodrig Our C++ guru: Nic Bone

Similar presentations


Presentation on theme: "TA: Maya Rodrig Our C++ guru: Nic Bone"— Presentation transcript:

1 TA: Maya Rodrig Our C++ guru: Nic Bone
CSE 326 TA: Maya Rodrig Our C++ guru: Nic Bone

2 Linux machines at UW Machine Names: Ceylon, Sumatra, Fiji, Tahiti
Access Use X-terminals in back of Sieg 329 (click on one of the Linux machines) Use Windows machines

3 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)

4 Unix Manual: ‘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. Keys: q – exit man Page Up Page Down

5 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:

6 Look at files in a class directory

7 File Permissions ‘w’ here means I can write to the files, but no-one
else can

8 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 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.

9 How to compile the program

10 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!

11 Edit runmaze.cpp – forgot &
Darn, now we lost this shell until we close emacs

12 Edit runmaze.cpp Current line number

13 Emacs keys CTRL-X S (hold down control for both letters) CTRL-X C
Save your work CTRL-X C Exit emacs CTRL-G Abort current command (if you accidentally typed something wrong) More: (Quick intro) (official documentation)

14 Intro to make – project file dependencies

15 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.

16 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

17 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++.

18 g++ compiling flags -c -Wall -g
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?

19 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)

20 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

21 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)

22 start it/set a couple of breakpoints
break gdbSquareMaze::getStartMazeNode is the form for putting a breakpoint on a C++ class method.

23 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.

24 More info 326 Computing page (more info on these tools) GNU Info pages
GNU Info pages Friendly people in lab / other students man command


Download ppt "TA: Maya Rodrig Our C++ guru: Nic Bone"

Similar presentations


Ads by Google