所有 Makefile 均已损坏

所有 Makefile 均已损坏

我无法再运行任何 Makefile。我得到:

./Makefile: line 1: sorter:: command not found

Makefile 的内容:

sorter: sorter.o
    gcc sorter.o -o sorter

sorter.o: sorter.c
    gcc -c sorter.c

test:
    ./run_test

check:
    c_style_check sorter.c

clean:
    rm -f sorter *.o

令人惊讶的是,就在昨天,我的所有 Makefile 都运行正常。我不知道发生了什么,我想我的 Lubuntu 进行了更新,但仅此而已。

答案1

发生该错误的原因是您希望 shell 能够理解并运行该文件。

Makefile 并不意味着是可执行的 - 它们作为命令的输入给出,make例如make -f Makefile- 或者只是make,因为它将在当前目录中搜索具有默认名称的文件,如Makefilemakefile

man make

   To  prepare to use make, you must write a file called the makefile that
   describes the relationships among files in your program, and the states
   the  commands for updating each file.  In a program, typically the exe‐
   cutable file is updated from object files, which are in  turn  made  by
   compiling source files.

   Once  a  suitable  makefile  exists,  each  time you change some source
   files, this simple shell command:

          make

   suffices to perform all necessary  recompilations.   The  make  program
   uses  the  makefile  description and the last-modification times of the
   files to decide which of the files need to be  updated.   For  each  of
   those files, it issues the commands recorded in the makefile.

   make  executes  commands  in  the makefile to update one or more target
   names, where name is typically a program.  If no -f option is  present,
   make  will  look for the makefiles GNUmakefile, makefile, and Makefile,
   in that order.

相关内容