【问题标题】:Qt: executable does not regeneratedQt:可执行文件未重新生成
【发布时间】:2013-01-21 06:45:38
【问题描述】:

我有简单的 Qt 程序。运行 make 时会出现 1200 行长的错误

make: Circular main.o <- QThread dependency dropped.
In file included from mythread.h:4,
                 from main.cpp:3:
./QThread:1: error: stray '\127' in program
./QThread:1: error: stray '\2' in program
./QThread:1: error: stray '\1' in program
./QThread:1: error: stray '\1' in program
In file included from mythread.h:4,
                 from main.cpp:3:
./QThread:1:8: warning: null character(s) ignored
./QThread:1: error: stray '\2' in program
./QThread:1:18: warning: null character(s) ignored
./QThread:1: error: expected constructor, destructor, or type conversion before '>' token
./QThread:1:20: warning: null character(s) ignored
./QThread:1: error: stray '\1' in program
./QThread:1:22: warning: null character(s) ignored
./QThread:1: error: stray '\240' in program
./QThread:1: error: stray '\21' in program
./QThread:1:28: warning: null character(s) ignored
./QThread:1: error: stray '@' in program
./QThread:1:34: warning: null character(s) ignored
./QThread:1: error: stray '@' in program
./QThread:1: error: stray '\24' in program
./QThread:1:43: warning: null character(s) ignored
./QThread:1:54: warning: null character(s) ignored
./QThread:1: error: stray '@' in program
./QThread:1:56: warning: null character(s) ignored
./QThread:1: error: stray '\8' in program
./QThread:1:58: warning: null character(s) ignored
./QThread:1:60: warning: null character(s) ignored

...

./QThread:16: error: stray '\255' in program
./QThread:16: error: stray '\255' in program
./QThread:16: error: stray '\235' in program
./QThread:16: error: stray '\156' in program
./QThread:16: error: stray '\137' in program
./QThread:16: error: stray '\195' in program
./QThread:16: error: stray '\199' in program
./QThread:16: error: stray '\144' in program
./QThread:16:252: warning: null character(s) ignored
./QThread:16: error: stray '@' in program
./QThread:16: error: stray '\139' in program
./QThread:16: error: stray '\16' in program
./QThread:16: error: stray '\240' in program
./QThread:16: error: stray '\255' in program
./QThread:16: error: stray '\8' in program
./QThread:16: error: stray '\15' in program
./QThread:16: error: stray '\149' in program
./QThread:16: error: stray '\194' in program
./QThread:16: error: stray '\132' in program
./QThread:16: error: stray '\210' in program
./QThread:16: error: stray '\139' in program
./QThread:16: error: expected declaration before '}' token
In file included from main.cpp:3:
mythread.h:1:1: unterminated #ifndef
make: *** [main.o] Error 1

QThread 是可执行文件。当我删除它并再次运行make 时,它编译正常。但是当我做一些更改时make 给了我同样的错误。我正在使用qmake 创建Makefile,为什么无法重新生成可执行文件?

QThread.pro
######################################################################
# Automatically generated by qmake (2.01a) Mon Jan 21 10:22:12 2013
######################################################################

TEMPLATE = app
TARGET = 

# Input
HEADERS += mythread.h
SOURCES += main.cpp mythread.cpp

【问题讨论】:

  • 在我看来,您的编辑器以解析器不支持的模式保存文件。检查保存选项。
  • 你能发布你的 .pro 文件的内容吗?看起来编译器可能正在尝试编译一个 .o 文件,就好像它是 C++ 源代码一样。 .pro 文件应包含程序中的 .cpp 文件列表,而不是 .o 文件。此外,命名您的可执行 QThread 可能是不明智的,因为这也是 Qt 类的名称;也许这会混淆 qmake/make 系统中的某些内容。
  • @JeremyFriesner 我更改了程序名称,它可以工作,谢谢。

标签: c++ qt executable


【解决方案1】:

您的mythread.h 执行#include &lt;QThread&gt;,当您自己的可执行文件命名为QThread 时,这会找到您刚刚构建的可执行文件,而不是Qt 自己的头文件。

您已根据 Jeremy 的评论重命名该程序,并且您已经看到它可以正常工作。这是一个不错的选择。另一个是确保你包含&lt;QThread&gt; 而不是"QThread"(如果你还没有这样做的话)并确保你的编译器标志设置为使得当前目录不会在Qt的头目录之前被搜索。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-26
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    相关资源
    最近更新 更多