【问题标题】:make clean results in no target with specific makefile namemake clean 导致没有具有特定 makefile 名称的目标
【发布时间】:2015-02-13 01:12:02
【问题描述】:

我在同一个项目目录下有很多makefile。

Makefile_prune:

OBJS    = main.o
SOURCE  = main.cpp
HEADER  =   Division_Euclidean_space.h  Find_diameter.h Find_k_max.h    Householder.h   IO.h    Mean_variance.h Point.h Random_generator.h  Random_kd_forest.h  Tree.h
OUT     =   rkd
CC  = g++
FLAGS   =   -std=c++0x  -O3 -c  -Wall
# -c flag generates object code for separate files

all: $(OBJS)
    $(CC)   $(OBJS) -o $(OUT)
    make clean

# create/compile the individual files >>separately<< 
main.o: main.cpp
    $(CC) $(FLAGS) main.cpp

.PHONY : all
# clean house
clean:
    rm -f $(OBJS)

# do a bit of accounting
count:
    wc $(SOURCE) $(HEADER)

我收到了清理错误,如下所示:

samaras@samaras-A15:~/code$ make -f Makefile_prune 
g++ -std=c++0x  -O3 -c  -Wall main.cpp
g++ main.o -o rkd
make clean
make[1]: Entering directory `/home/samaras/paper/rkd_forest/code'
make[1]: *** No rule to make target `clean'.  Stop.
make[1]: Leaving directory `/home/samaras/paper/rkd_forest/code'
make: *** [all] Error 2

然后我可以运行make -f Makefile_prune clean,它将执行清理工作,但我想要单人命令,我的意思是,不必按两次回车。

相关答案:

  1. “make clean” results in “No rule to make target `clean'”
  2. gcc makefile error: “No rule to make target …”

想法:

makefile 实际上是用于我的 C 项目的,我只是做了一些更改以适应 C++,也许这就是问题所在。

【问题讨论】:

    标签: c++ gcc makefile g++


    【解决方案1】:

    我认为您需要致电make -f Makefile_prune clean

    调用make clean 时,因为您没有使用-f 选项,它不会调用Makefile_prune。它调用其他一些名为“Makefile”的文件,该文件可能没有clean 目标。

    另请参考:https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html

    【讨论】:

    • 不,有不止一个 Makefile。我做了这个make -f clean,但还是不行。
    • 你试过make -f Makefile_prune clean 吗?
    • 正确!我建议你用那个更新你的问题! +1。猜猜我是睡觉的人;)顺便说一句,网页不错。
    • 哈哈!有时我们都会犯愚蠢的错误。我发现自己睡了很多次!感谢您的称赞和访问!
    【解决方案2】:

    如果没有必要,请勿从您的makefile 内部拨打make。在这种情况下,您绝对不会:

    all: $(OUT) clean
    
    clean : $(OUT)
        rm -f $(OBJS)
    
    $(OUT) : $(OBJS) 
        $(CC) $(OBJS) -o $(OUT)
    

    这肯定会更快,因为您不必掏钱。此外,如果您再次运行make,您将不必重建rkd。不过,如果您想每次都重建它,请将 $(OUT) 替换为一些 PHONY 规则(例如 clean : buildbuild : $(OBJS)

    另外,cleancount 应该是 PHONY

    .PHONY : all clean count
    

    最后,值得指出的一件事。您没有手动删除*.o 文件。 make 应该为您删除它们。见Chained Rules

    【讨论】:

    • 这个答案也不错,但是按照时间顺序,我会保留另一个作为选定的,+1!
    猜你喜欢
    • 2013-01-02
    • 1970-01-01
    • 2011-05-10
    • 2014-03-23
    • 2023-03-09
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多