Project Build Notes

Find a place to put the project. I recommend that you create a directory for all your comp217 projects. In that directory, create a new directory for each lab. In my case, I am putting this code in the code directory under my comp217 directory.

/space/home/staff/d99110215/comp217/code

Then I made a directory called circuit1 for this project and cd'ed into it.

--> mkdir circuit1
--> cd circuit1

There were initially no files in the directory. I created a file ending in .c to contain the source code for the circuit1.c. The .c ending is the usual one for C programs. Also acceptable are cc, CC and cpp. To compile the program we use the g++ compiler. This is designed for C++ but will work fine on standard C programs. The -o option is used to give a name to the executable program.

--> g++ -o circuit1 circuit1.c

After compilation completes, assuming no errors (They will be discussed in some other notes), there will be two files in the directory.

--> ls
circuit1*  circuit1.c
--> ls -l
total 20
-rwxrwxr-x    1 d99110215 d99110215    13941 Mar 29 16:57 circuit1*
-rw-rw-r--    1 d99110215 d99110215      445 Mar 29 16:56 circuit1.c

The circuit1 file is the executable. Notice that the x options are turned on and that it is significally larger than the .c file. Normally, you run a program in UNIX by typing its name. This is true of our program as well. However, the shell searches through the list of directories in the PATH variable to find the program. The directory we are in is not in that list so it won't run the program.

--> circuit1
shell: circuit1: command not found

If we give the shell a path to the executable, it will run it without looking in the PATH. We could give the full path which is:

/space/home/staff/d99110215/comp217/code/circuit1/circuit1
But this is a lot of typing. As we discussed in the notes about the file system, there is a shorthand name for the directory we are currently in. This is . (period). So a shorthand way to give the path to the program is ./circuit1.

--> ./circuit1
Enter a voltage in volts 10
Enter a resistance in ohms 10
The power is 100 watts
The current is 10 amperes

The prgram runs, prompting us for the two numbers. My responses are in bold above and the rest is the program output.