1

When I rewrite pset3's programs associated with Stanford Portable Library (SPL) on my own, they always fail to compile even though I write them out exactly the same as the original program. For example, when I write click.c and attempt to compile it, an error is reported that window is an unused variable, while in the original program it works just fine.

Why does this happen?

1 Answer 1

2

Be sure that you have Makefile from the src4m file in the same directory and use make click to compile. This Makefile contains compilation rules for each specific file that override the generic one of the default make command.

The "unused variable" error is actually a warning, but the default compilation command toggles the -Werror option, which treats all warnings as errors.

In the case of click.c, Makefile specifies an additional option, -Wno-unused-variable, which ignores the warning.

The full compilation command listed in Makefile for click.c is as follows.

clang -ggdb3 -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o click click.c -lcs -lm

You could try to use that command when you compile the file if you don't want to use the provided Makefile.

3
  • Thanks, this does help. However, I have another problem now. I wrote the compile definition of my own SPL program, which is mywindow, into Makefile, and it solved the compile problem, but when I run the program with ./mywindow, it says no such file or directory, why?
    – eifphysics
    Commented Jan 7, 2015 at 23:36
  • @MinjiLei It sounds like you may have forgotten to change the name of the output file in the compile definition. This is the name following the -o option ("o" stands for "output"), which is window in the provided Makefile. Have you changed this to mywindow?
    – Chrisuu
    Commented Jan 7, 2015 at 23:46
  • @MinjiLei By the way, if the answer helped, please don't forget to 'accept' it to indicate the problem was solved. You can do that by clicking the checkmark next to it.
    – Chrisuu
    Commented Jan 9, 2015 at 2:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .