Qt 编译器警告:覆盖目标命令/忽略目标旧命令

发布于 2024-10-12 20:51:30 字数 282 浏览 15 评论 0原文

当我为 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'

我认为它们表明我的项目配置存在问题,问题是什么以及如何修复它?

When I'm compiling my Qt project for Windows I receive these 2 warnings:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赠意 2024-10-19 20:51:30

我曾经遇到过同样的错误,也许你的问题根源不同,但无论如何我都会写。
在我的 *.pro 文件中,它就像:

SOURCES += main.cpp\
    mainwindow.cpp\
    serialHelper.cpp \
serialHelper.cpp

HEADERS  += mainwindow.h\
     += serialHelper.h \
serialHelper.h \
typeDefinitions.h

cpp 和头文件重复自身。我删除了重复的包含并为我解决了问题。

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 :

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 .

原来是傀儡 2024-10-19 20:51:30

在很多情况下,此错误与 QMake 只是将所有目标文件放入构建目录中的平面文件夹中有关,如果两个源文件具有相同的名称,即使它们可能位于不同的文件夹中,也会导致问题。例如

SOURCES += foo.cpp
SOURCES += bar.cpp
SOURCES += bla/foo.cpp
SOURCES += bla/bar.cpp

在这种情况下,QMake 会抱怨 foo.o 和 bar.o。

此问题的解决方案是添加

CONFIG += object_parallel_to_source

到 .pro 文件,这将使构建文件夹镜像源树的文件夹层次结构。不知道为什么这不是默认值。

问题和解决方案之前已在此处指出,但未在此线程中讨论的警告消息的上下文中指出。

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

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.

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.

The problem and solution have been previously pointed out here but not in the context of the warning message discussed in this thread.

得不到的就毁灭 2024-10-19 20:51:30

make clean 然后 make 应该可以解决这个问题。 :) (或者右键单击 Qt Creator 中的项目 -> Clean,然后右键单击 Qt Creator 中的项目 -> Rebuild)。

如果不起作用,请手动删除makefile并重建然后项目。

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).

If it does not work, manually delete the makefile and the rebuild then project.

等你爱我 2024-10-19 20:51:30

我也遇到了同样的问题——Makefile 两次包含相同的 .cpp 和 .h 文件,并且给了我的多重定义。首先在这里定义错误。

事实证明,除了 *.pro 文件之外,相关的 .cpp 和 .h 文件也已添加为 qwtfunctions。因此,如果上述答案都不适合您,请检查 qwtfunctions。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文