首页 > 解决方案 > 使用make时没有这样的文件或目录错误

问题描述

我对 Linux 还比较陌生,但我的操作系统课程中有一个涉及多个文件的作业。我的教授给了我们他的makefile,但它对我不起作用。Make 只返回错误。我知道我拥有与教授相同的所有文件,虽然我的还没有完成,但我没有理由看到代码无法编译。

这是生成文件:

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

这是我收到的错误消息:

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$

我看到教授在课堂上编译和运行代码,所以我知道它有可能工作,但它给我带来了问题。我很乐意提供更多信息或代码,但我认为文件的内容与编译错误无关。谢谢!

标签: clinuxmakefilepthreadscc

解决方案


我很确定这是您的 makefile 的预期源代码,它既有效又有效:

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

您的 makefile 的问题是:

  1. 没有默认目标,即缺失all:
  2. ln -sf sync assn4被用作编译器参数

此外,请确保命令行(例如,${CC} ...)始终以 TAB 字符开头。我无法判断您的代码块中是否有一些,因为它们在这里自动更改为空格,但想指出。


推荐阅读