C++ Makefile问题:错误127,255,正在Makefile中运行程序

C++ Makefile问题:错误127,255,正在Makefile中运行程序,c++,c,makefile,C++,C,Makefile,我是ECE的一名学生,从事编程作业;它已经提交并正在评分,但我仍然想知道为什么我的makefile不能工作。当我在学校服务器上用“maketests”命令运行文件时,它会响应 '找不到make:testq:command。 make*测试错误127 如果我运行“maketestq12345”,它实际上会运行我的程序“myar”并生成输出文件,但它会给出一个错误255。我不理解这个问题,或者为什么makefile找不到目标。我通过stackoverflow和其他来源搜索了这些错误,但不理解,也找不

我是ECE的一名学生,从事编程作业;它已经提交并正在评分,但我仍然想知道为什么我的makefile不能工作。当我在学校服务器上用“maketests”命令运行文件时,它会响应

'找不到make:testq:command。 make*测试错误127

如果我运行“maketestq12345”,它实际上会运行我的程序“myar”并生成输出文件,但它会给出一个错误255。我不理解这个问题,或者为什么makefile找不到目标。我通过stackoverflow和其他来源搜索了这些错误,但不理解,也找不到可行的解决方案。如果重要的话,我会在Linux服务器上运行它

我在CS311/Homework4/test中运行它,其中包含makefile、程序和文本文件

感谢您的时间和帮助;谢谢

#
#  $RCSfile$
#  $Revision$
#  $Author$
#  $Date$
#  $Log$
#
# Author: Cody R Crawford
# Email: crawfoco@onid.orst.edu
# Course: CS311-400
# Homework: 4
# Citations:
#   http://mrbook.org/tutorials/make/
#       For examples, guidance, and genera understanding
# Assumptions: I assume you want the .o files to show up unless 
# you specifically command 'clean'
#########################################################

CC=gcc
DEBUG=-g
CFLAGS=$(DEBUG) -Wall
PROGS=sig_demo myar 
OBJECTS=$(PROGS:.c=.o)

all: $(PROGS)

sig_demo.o: sig_demo.c
    $(CC) $(CFLAGS) -c sig_demo.c

sig_demo.c: sig_demo.o
    $(CC) $(CFLAGS) -c sig_demo.c

myar.o: myar.c
    $(CC) $(CFLAGS) -c myar.c

myar.c: myar.o
    $(CC) $(CFLAGS) -c myar.c

tests:
    testq
    testt
    testv

testq:
    testq24 
    testq135
    testq12345

testq24:
    rm -f ar24.ar 
    ar q ar24.ar 2-s.txt 4-s.txt
    myar q myar24.ar 2-s.txt 4-s.txt 
    diff ar24.ar myar24.ar

testq135:
    rm -f ar135.ar 
    ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt 
    myar q myar135.ar 1-s.txt 3-s.txt 5-s.txt 
    diff ar135.ar myar135.ar

testq12345:
    rm -f ar12345.ar 
    rm -f myar12345.ar
    ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
    ./myar -q myar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
    diff ar135.ar myar135.ar

testt:
    testt24
    testt135
    testt12345

testt24:
    rm -f ar24.ar
    ar q ar24.ar 2-s.txt 4-s.txt
    ar t ar24.ar > ar-ctoc.txt 
    myar -t ar24.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt 

testt135:
    rm -f ar135.ar
    ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt
    ar t ar135.ar > ar-ctoc.txt 
    myar -t ar135.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt 

testt12345:
    rm -f ar12345.ar
    ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
    ar t ar12345.ar > ar-ctoc.txt 
    myar -t ar12345.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt  

testv:
    testv24
    testv135
    testv12345

testv24:
    rm -f ar24.ar
    ar q ar24.ar 2-s.txt 4-s.txt
    ar v ar24.ar > ar-ctoc.txt 
    myar -v ar24.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt 

testv135:
    rm -f ar135.ar
    ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt
    ar v ar135.ar > ar-ctoc.txt 
    myar -v ar135.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt 

testv12345:
    rm -f ar12345.ar
    ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
    ar v ar12345.ar > ar-ctoc.txt 
    myar -v ar12345.ar > myar-ctoc.txt 
    diff ar-ctoc.txt myar-ctoc.txt 




clean:
    rm -f $(PROGS) $(OBJECTS) *.o *~
应列在同一行上,否则将尝试将其作为命令执行

比如,

tests:
    testq
    testt
    testv
将只尝试执行shell命令
testq
testt
testv
,这些命令不存在,并给出您的错误

tests: testq testt testv

只需确保在执行目标测试之前完成makefile目标
testq
testt
testv
。在本例中,
测试
不包含任何命令,因此target所做的唯一事情就是确保执行depdenicies。

我想您正在寻找:

简单的生成文件由以下形状的“规则”组成:

target ... : dependencies ...
        command
        ...
        ...
这是您需要解决的问题:

tests: testq testt testv

testq: testq24 testq135 testq12345

testv: testv24 testv135 testv12345

这是大量的
makefile
。你能把它简化成一个最小的测试用例吗?当然可以。它所做的是在make运行时编译sig_demo.c和myar.c。(很抱歉,我不理解注释的代码标记语法)
gcc-g-Wall-csig_demo.c
gcc-sig_demo.o-osig_demo
gcc-g-Wall-cmyar.c
gcc-myar.o-omyar
,一切正常。如果要运行
make测试
:将发生以下情况:
testq
make:testq:command not found
make:**[tests]错误127
。如果我运行
make:testq24
我会收到:
rm-f ar24.ar
ar q ar24.ar 2-s.txt 4-s.txt
ar:creating ar24.ar
myar q myar24.ar 2-s.txt 4-s.txt
make:myar:command not found
make:**[testq24]错误127
,因为此生成文件的目标是在程序上运行测试,这是我对
ar
命令的实现(实际上并非100%完全符合规范)。运行
make
用于编译,
makeclean
用于移除排泄物,
maketests
用于在各种测试目标中运行命令。谢谢!现在第二个问题是它可以运行testq(因此也可以运行testq24),但会产生以下错误:
make:**[testq24]error 127
。如果我将
myar…
更改为
/myar
。。。它给出了
make:**[testq24]错误255
。我觉得它只是看不到本地文件夹,我如何给它一个路径?@Borne2Run\u When\u SegFault:您也可以使用绝对路径,或者您可以将Makefile的当前目录重用为:
current\u dir=$(shell pwd)
current\u dir=$(notdir$(shell pwd))