找不到命令,make:错误127,

时间:2015-04-13 07:59:31

标签: c++ makefile g++ flex-lexer

我有这个成功编译的make文件:

CCC = g++
CFLAGS = -c -g -Wall
CCFLAGS = $(CFLAGS)
LDFLAGS = -g

common_objects = main.o tokens.o
flex_objects = flex_scanner.o 
hand_objects = hand_scanner.o 

both: flex_scanner hand_scanner

flex_scanner: $(flex_objects) $(common_objects)
    $(CCC) $(LDFLAGS) $(flex_objects) $(common_objects) -o flex_scanner

flex_scanner.o: flex_scanner.l
    flex -it flex_scanner.l > flex_scanner.cc
    $(CCC) $(CCFLAGS) flex_scanner.cc

clean:
    /bin/rm -f hand_scanner flex_scanner $(hand_objects) $(flex_objects) \
        $(common_objects) flex_scanner.cc

test: both
    flex_scanner < test1 > flex_test1.output
    hand_scanner < test1 > hand_test1.output

但是当我尝试运行make test时,我收到以下错误:

flex_scanner < test1 > flex_test1.output
/bin/sh: flex scanner:command not found
make *** [test] Error 127

这个错误是什么意思?

1 个答案:

答案 0 :(得分:0)

The question has been answered in the comments. Converted to a community wiki answer to suit the Q&A format of Stackoverflow)。

正如@Brett Hale ./flex_scanner所指出的那样:

test: both
    ./flex_scanner < test1 > flex_test1.output
    hand_scanner < test1 > hand_test1.output

@Beta对此进行了解释:

  

当您提供flex_scanner之类的命令时,您的操作系统必须按该名称查找可执行文件。它有一个查找这些东西的地方列表,可能包括也可能不包括“。” (对于工作目录)。通过添加“./”,你告诉操作系统“不要去寻找'flex_scanner'之类的东西,使用我给你的路径”。

现在,我可以修改PATH,如@JJoao所解释的那样:

  

如果您不在恶意机器中,可以添加导出PATH = $ PATH:。到你的〜/ .bashrc或类似的,来搜索当前目录中的命令。

或者可能不那么有用的二进制文件可以通过链接添加到PATH目录中,如@Wojciech Frohmberg所解释的那样:

  

或者你可以ln -s ~/bin/flex_scanner /path_to_exec/flex_scannerln -s ~/bin/hand_scanner /path_to_exec/hand_scanner

大多数有经验的unix用户都会避免在.上使用PATH,因为它会冒着运行意外二进制文件的风险。