0

I am still relatively new to Linux, but I have an assignment in my operating systems class that involves several files. My professor gave us his makefile, but it isn't working for me. Make just returns errors. I know that I have all of the same files as my professor and, although mine aren't done yet, there is no reason I see for the code to not compile.

Here is the Makefile:

sync: sync.c prodcons.c prodcons.h producer.c producer.h consumer.c consumer.h Makefile
        ${CC} -g -Wall -pthread -o  sync ssync.c prodcons.c producer.c consumer.c ln -sf sync assn4

and here is the error message I am getting:

J_studentid@cs3060:~/assn4$ make
cc -g -Wall -pthread -o sync sync.c prodcons.c producer.c consumer.c ln -sf sync assn4
cc: error: ln: No such file or directory
cc: error: sync: No such file or directory
cc: error: assn4: No such file or directory
cc: error: unrecognized command line option ‘-sf’; did you mean ‘-Hf’?
Makefile:2: recipe for target 'sync' failed
make: *** [sync] Error 1
J_studentid@cs3060:~/assn4$

I saw the professor compile and run the code in class, so I know it has the potential to work, but it is giving me problems. I am more than happy to provide more information or code, but I don't think the contents of the files is relevant to the compilation errors. Thank you!

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
Westyn D
  • 123
  • 9
  • 1
    That surely can't be the full or exact makefile given to you (unless your prof has no idea what he/she is doing). It isn't even syntactically correct and is not a makefile at all (it's a shell script at best). If you want to run those commands then you need to put the `ln` part on a new line. The `${CC}` and the `ln` are two seperate commands – kaylum Mar 13 '21 at 03:38
  • 1
    You pass `ln -sf sync assn4` as arguments to `cc`. That `ln` command should be on its separate line in your makefile. – Some programmer dude Mar 13 '21 at 03:38
  • Thank you both, that worked. I thought it looked weird when my prof showed us the code, but I didn't even think that it might be incorrect. – Westyn D Mar 13 '21 at 04:24
  • @WestynD: I showed and explained a minimal but very flexible Makefile skeleton [here](https://stackoverflow.com/a/66576812/15296379) a couple of days ago. You might find it useful – perhaps not for assignments, but for your own stuff. Makefiles are supposed to make life easier, not harder! ;-) – Glärbo Mar 13 '21 at 15:42

1 Answers1

2

I am pretty sure that this is the intended source code of your makefile that is both valid and working:

all:
    ${CC} -g -Wall -pthread -o  sync ssync.c prodcons.c producer.c consumer.c
    ln -sf sync assn4

Issues with your makefile were:

  1. No default target, i.e. missing all:
  2. ln -sf sync assn4 were used as compiler arguments

Also, please make sure that the command lines (e.g., ${CC} ...) always start with a TAB character. I cannot tell whether there was some in your codeblock since they are changed to spaces automatically here but wanted to point out.

  • 1
    This answer is partially based in faulty code formatting in the question, which altered the appearance of the Makefile. The `make` output the OP reported was a clue about that. I have since corrected OP's formatting. But your point (2) is correct, and it appears to explain the nature of the problem. Your point about leading tab characters on recipe lines is also well taken. – John Bollinger Mar 13 '21 at 18:27
  • 1
    I recall (GNU) make will make the first make target as the default, so there is nothing special about. ’all’ target other than appearing first. But i agree it is clearer to have default target named and not use the actual build target. And ’all’ is what people expect. The default target should also be marked phony and depend on ’sync assn4’… – FooF Mar 14 '21 at 03:02