| OpSys Spring 2005 - HW1 FAQ |
|   OpSys Home   |   HW1 Assignment |
+ Using Make
|
Question: | How do I use the Unix |
|
Answer: | First you need to create a file named A Makefile can contain lots of things including definitions, generic rules and specific rules. For now I'll only discuss using specific rules, check the man page for make (or check out the GNU Make manual) for a complete description of all the possibilities... A rule in a Makefile includes three basic elements:
The syntax for this is shown below:
target: dependencies ...
commands
...
IMPORTANT!: The command line(s) must start with a tab character! Here is a rather simple Makefile that will build an executable named "hw1" from a C program named "hw1.c" using gcc:
Here is another Makefile, this one will build an executable named "hw1" from two C files: "hw1main.c" and "hw1subs.c", and will include the readline and curses libraries (including paths to the includes and library as is needed on CS FreeBSD machines).
|
+ What is -Wall ?
|
Question: | What is gcc -Wall -o hw1 hw1.c |
|
Answer: |
|
+ Using code in homework writeup
|
Question: | Can we use the code provided in the homework writeup as a starting
point? Specifically, can we use the code from |
|
Answer: | Yes, feel free to use any of the code you find helpful. It is assumed
that you use the code in |
+ Problems with the setenv man page
|
Question: | I type |
|
Answer: | There is a command named man 3 setenv The 3 tells man to look in section 3. Section 1 are user commands, section 2 are system calls, section 3 are library functions (there are more sections as well...). |
+ Compiler Issues (like syntax error before 'int')
|
Question: | I keep getting a compiler error - it doesn't seem to like my variable declarations. What's up? |
|
Answer: | Traditional C does not allow you to declare any variables in a function after you have some lines of code (non-declarations). So something like this won't work:
void blah(){
int i;
for (i=0;i<100;i++) {
printf("i is %d\n",i);
}
int j;
for (j=0;j<100;j++) {
printf("j is %d\n",j);
}
}
You would need to declare j before the first loop:
void blah(){
int i;
int j;
for (i=0;i<100;i++) {
printf("i is %d\n",i);
}
for (j=0;j<100;j++) {
printf("j is %d\n",j);
}
}
Note that the C99 standard does allow declaring variable in the middle of a function. On the CS freebsd machines you can use gcc3 instead of gcc, it supports the C99 standard. You can get the details of C99 support in gcc3 here: http://gcc.gnu.org/c99status.html |
+ Which Environment Variables should exist?
|
Question: | The assignment indicates that we need to be able to access existing environment variables, like those shown when we type "set" into BASH. My program can't seem to find all of them - what am I doing wrong? |
|
Answer: | Some of the variables you see with the PATH HOME PWD You can also create your own environment variables (tell the shell to add a new environment variable before you run your program): bash> export JOE=FRED bash> ./hw1 hw1prompt> print JOE JOE = FRED |