所有 Makefile 都已损坏

ItM*_*ItM 3 makefile make

我不能再运行任何 Makefile 了。我得到:

./Makefile: line 1: sorter:: command not found
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,就在昨天,我所有的 Makefile 过去都运行良好。我不知道发生了什么,我想我的 Lubuntu 有更新,但就是这样。

ste*_*ver 7

发生错误是因为您希望 shell 理解并运行该文件。

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

来自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.
Run Code Online (Sandbox Code Playgroud)

  • 话虽如此,您可以对 makefile 使用 shebang 使它们表现得像可执行文件:`#!/usr/bin/make -f` (3认同)