【发布时间】:2020-03-22 04:39:36
【问题描述】:
这是我的生成文件:
LIBS = libxml2.so.2.9.4
LDFLAGS = -lstdc++ -lpthread -lxml2
vpath %.hpp ./
vpath %.cpp ./
vpath %.h ./libxml2/include/libxml
all: KeyGenerator
KeyGenerator: main.o ProjectXmlParser.o xmlparser.o
g++ ${CXXFLAGS} ${LDFLAGS} -o KeyGenerator $+ ${LIBS}
main.o: main.cpp
ProjectXmlParser.o: ProjectXmlParser.cpp ProjectXmlParser.hpp
xmlparser.o: xmlparser.cpp xmlparser.hpp global.hpp
phony: clean
clean:
rm -f *.o
输出:
/usr/bin/make -f Makefile CONF=Debug
g++ -g -Wall -std=gnu++11 -pthread -I./ -I./src -I./libxml2/include -lstdc++ -lpthread -lxml2 -o KeyGenerator main.o ProjectXmlParser.o xmlparser.o libxml2.so.2.9.4
g++: error: ProjectXmlParser.o: No such file or directory
g++: error: xmlparser.o: No such file or directory
Makefile:12: recipe for target 'KeyGenerator' failed
make: *** [KeyGenerator] Error 1
在项目目录中,我所有的 hpp 和 cpp 文件都存在于同一级别。我确实有另一个正在使用的名为 libxml 的项目。当我进行构建时,会创建 main.o,但没有创建任何 .o 文件。我已经看到其他帖子提出了这个问题,但到目前为止,没有任何东西对我有用。
谢谢。
【问题讨论】:
-
您尚未定义如何创建目标文件的方法
-
您希望 makefile 中的哪一行触发丢失的 .o 文件的生成以及如何触发?
-
如果注释掉
vpath指令会发生什么? -
@Jacob GNU Make 为此使用 implicit rules。
-
根据您提供的信息,您不应该收到此错误,这意味着您没有告诉我们有问题。此处的 makefile 与您的实际 makefile 在某些实质性方面有所不同,或者有些奇怪。您向我们显示了错误消息,但没有显示编译行 make run;这些会很有帮助。此外,您可以运行
make -d并检查输出以了解 make 如何处理ProjectXmlParser.o文件。