为什么我的 MakeFile 会出现“找不到命令”,即使该文件仍然有效?

问题描述 投票:0回答:1

我制作了一个 MakeFile 来运行我的 C 程序。我使用 vscode bash 终端通过

./MakeFile
运行 makefile。当我初始化它时,我收到一串错误,显示
command not found
,然后是我的 C 脚本的输出。

这是一个例子:

$ ./MakeFile
./MakeFile: line 1: obj_files: command not found
./MakeFile: line 2: all:: command not found
./MakeFile: line 3: Prog: command not found
./MakeFile: line 5: obj_files: command not found
./MakeFile: line 5: Prog:: command not found
./MakeFile: line 8: output:: command not found
This is for variable assignment.
./MakeFile: line 9:  1465 Segmentation fault      ./Prog
./MakeFile: line 11: clean:: command not found

这是我设置的MakeFile:

obj_files = stringManipulation.c Lexer/InstructionEvaluators/variable.c Lexer/lexer.c main.c 
all: 
    Prog output clean

Prog: $(obj_files)
    gcc -o Prog stringManipulation.c Lexer/InstructionEvaluators/variable.c Lexer/lexer.c main.c -I.

output: Prog  
    ./Prog
    
clean:
    rm ./Prog 

我尝试更改命令的顺序,但它根本没有改变任何东西。

c bash makefile
1个回答
0
投票

Makefile 不是由 shell 运行的脚本。当您说

./Makefile
时,大概对文件具有
x
权限,默认情况下它会被解释为 shell 脚本。您打算直接运行 make,它会自动在 pwd 中查找
Makefile
makefile
文件。理论上,如果您坚持输入 ./Makefile 而不是
make
,则可以在 makefile 中添加
shebang
,但这会很不寻常。例如:
#!/usr/bin/make
.

如果你确定 make 已安装,但你的 shell 找不到它,这意味着它的安装目录不在你的

PATH
环境变量中。您可以显式指定 make 二进制文件的绝对路径或将其目录添加到
PATH

© www.soinside.com 2019 - 2024. All rights reserved.