C++ Qt 编译器警告:覆盖目标的命令/忽略目标的旧命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4722400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt compiler warning: overriding commands for target / ignoring old commands for target
提问by sashoalm
When I'm compiling my Qt project for Windows I receive these 2 warnings:
当我为 Windows 编译 Qt 项目时,我收到以下 2 个警告:
Makefile.Debug:109: warning: overriding commands for target `debug/moc_mainwindow.cpp'
Makefile.Debug:106: warning: ignoring old commands for target `debug/moc_mainwindow.cpp'
I assume they indicate some problem with my project config, what is the problem and how do I fix it?
我认为他们表明我的项目配置存在一些问题,问题是什么,我该如何解决?
回答by Kadir Erdem Demir
I got the same error once , maybe source of your problem is different but I will write anyways. In my *.pro file, it was like :
我有一次遇到同样的错误,也许你的问题来源不同,但我还是会写。在我的 *.pro 文件中,它就像:
SOURCES += main.cpp\
mainwindow.cpp\
serialHelper.cpp \
serialHelper.cpp
HEADERS += mainwindow.h\
+= serialHelper.h \
serialHelper.h \
typeDefinitions.h
cpp and header file was repeating itself. I delete the repeating includes and problem solved for me .
cpp 和头文件在重复。我删除了重复的包含并为我解决了问题。
回答by rsp1984
In a lot of cases this error is related to QMake just putting all the object files in a flat folder in the build directory, which then causes problems if two source files have the same name, even though they might be in different folders. Such as
在很多情况下,此错误与 QMake 只是将所有目标文件放在构建目录中的一个平面文件夹中有关,如果两个源文件具有相同的名称,即使它们可能位于不同的文件夹中,也会导致问题。如
SOURCES += foo.cpp
SOURCES += bar.cpp
SOURCES += bla/foo.cpp
SOURCES += bla/bar.cpp
In this case QMake would complain about both foo.o and bar.o.
在这种情况下,QMake 会同时抱怨 foo.o 和 bar.o。
The solution to this problem is to add
这个问题的解决方案是添加
CONFIG += object_parallel_to_source
to the .pro file which will cause the build folder to mirror the folder hierarchy of the source tree. Not sure why this isn't the default.
到 .pro 文件,这将导致构建文件夹镜像源树的文件夹层次结构。不知道为什么这不是默认值。
The problem and solution have been previously pointed out herebut not in the context of the warning message discussed in this thread.
问题和解决方案先前已在此处指出,但未在此线程中讨论的警告消息的上下文中指出。
回答by Palmik
make clean
and then make
should solve this problem. :) (Or right click on project in Qt Creator -> Clean and then right click on project in Qt Creator -> Rebuild).
make clean
然后make
应该解决这个问题。:)(或者在 Qt Creator 中右键单击项目 -> Clean 然后在 Qt Creator 中右键单击项目 -> Rebuild)。
If it does not work, manually delete the makefile and the rebuild then project.
如果它不起作用,请手动删除makefile和rebuild then project。
回答by coding_n00b
I've had the same issue as well -- Makefile included the same .cpp and .h file twice, and was giving me Multiple definition of <class/function> first defined here
errors.
我也遇到了同样的问题——Makefile 两次包含相同的 .cpp 和 .h 文件,并且给了我Multiple definition of <class/function> first defined here
错误。
Turns out the .cpp and .h files in question were already added as qwtfunctions, in addition to being in *.pro file. So check qwtfunctions as well if none of the above answers worked for you.
原来有问题的 .cpp 和 .h 文件已经添加为 qwtfunctions,除了在 *.pro 文件中。因此,如果上述答案都不适合您,请检查 qwtfunctions 。