简体   繁体   English

makefile只为头文件生成文件对象吗?

[英]makefile generate file object for the header file only?

im having probleme in makefile . 我在makefile when i execute make commande in the terminal it has to generate header.o and main.o and then combine them to generate the excutable kmeans.o file,but it did not, it only generate header.o which is km.o and stop without any error message. 当我在终端中执行make commande时,它必须生成header.omain.o ,然后将它们组合以生成可执行的kmeans.o文件,但没有,它仅生成header.okm.o并停止没有任何错误信息。

this is my make file : 这是我的make文件:

CFLAGS = -ggdb
DEFINES = -DDEBUGGA
INCLUDES = 
LIBS = -lstdc++
EXAMPLE = kmeans.o
CC=g++

.cpp.o:
    $(CC) -c $(CFLAGS) $(DEFINES) $(INCLUDES) $<

all::   km.o kmeans.o 

km.o:   km.cpp km.hpp
gnuplot_i.o:    gnuplot_i.hpp
kmeans.o:   main.cpp

kmeans: $(EXAMPLE)
    $(CC) -o $@ $(CFLAGS) $(EXAMPLE) $(LIBS)

clean: 
    rm -f $(EXAMPLE) kmeans

The km.cpp and km.hpp is the header file and it implementation. km.cppkm.hpp是头文件及其实现。 gnuplot_i.hpp is header with its implementation. gnuplot_i.hpp是其实现的标头。 main.cpp file the file which links all these libries. main.cpp文件链接所有这些库的文件。

The default target in this makefile is all: km.o kmeans.o . 此makefile中的默认目标是all: km.o kmeans.o

So when you run make that is what will run. 因此,当您运行make ,它将运行。 So make will create those two .o files and stop. 因此,make将创建这两个.o文件并停止。

If you want make to be the same as make kmeans then you need all: kmeans as your default rule or to move the kmeans target above the all target (since the first target is the default one). 如果要使makemake kmeans相同,则需要all: kmeans作为默认规则,或将kmeans目标移至all目标之上(因为第一个目标是默认目标)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM