Dr. Dichter Fall 2000 Handout 2 University of Bridgeport This handout will go through the process of how to create, compile, and run the same program, sayTest, as handout 1. In UNIX, you need the help of some editor. A common one is vi, although it is not necessarily the easiest to with which to start. However, the basics of vi are fairly easy. Another simple editor on UNIX is pico. The lab instructor will help you in selecting and using a UNIX editor on our Solaris workstation. The first thing you need to do is to log in to our system. Once you log in, you are by default in your home directory. The lab instructor will guide you to using simple commands, such as pwd, cd, mkdir, cd .., ls. In addition, you become familiar with our C++ compiler, g++. Here we check the location of the current directory. It shows it is my home directory ( /home/dichter ), and then in a subdirectory program1, and another one called say. axon% pwd /home/dichter/cs101/program1/say Here, we do a directory listing ( all files, long listing ) axon% ls -al total 687 drwx------ 2 dichter 512 Aug 31 14:04 . drwxr-xr-x 4 dichter 512 Sep 1 1999 .. -rw------- 1 dichter 1031 Aug 31 14:04 .nfs2138 -rw------- 1 dichter 288 Sep 1 1999 Talker.cpp -rw------- 1 dichter 126 Sep 1 1999 Talker.h -rwx------ 1 dichter 680724 Sep 1 1999 a.out -rw------- 1 dichter 0 Aug 31 14:04 done -rw------- 1 dichter 187 Sep 1 1999 sayTest.cpp Here, we compile only ( -c ) the source code Talker.cpp. axon% g++ -c Talker.cpp The directory listing below shows a new file Talker.o. This file is generated by the compile above. axon% ls -al total 690 drwx------ 2 dichter 512 Aug 31 14:05 . drwxr-xr-x 4 dichter 512 Sep 1 1999 .. -rw------- 1 dichter 1031 Aug 31 14:04 .nfs2138 -rw------- 1 dichter 288 Sep 1 1999 Talker.cpp -rw------- 1 dichter 126 Sep 1 1999 Talker.h -rw------- 1 dichter 2248 Aug 31 14:05 Talker.o -rwx------ 1 dichter 680724 Sep 1 1999 a.out -rw------- 1 dichter 0 Aug 31 14:04 done -rw------- 1 dichter 187 Sep 1 1999 sayTest.cpp Below, we compile only the other source code, sayTest.cpp. Similarly, this produces a file, sayTest.o. If the file had errors in it, we would have gotten a list of errors to be corrected. axon% g++ -c sayTest.cpp Below, we compile and link the two modules. The lack of the switch -c, means it is not compile only. It is compile then link the modules into a single program. The -o switch followed by a name instructs the system to produce a working program under the name prog. Any other name might have been chosen. axon% g++ -o prog Talker.cpp sayTest.cpp Below, we run the compiled program, and the output is the same as the program we built in the VC++ environment. axon% prog I Love C++ hmmmmmmmm I love Java axon%