Qt程序编译失败
Qt program fails to compile
我正在编写这个简单的Qt应用程序,但它显示以下错误。谁能解释我为什么会出现这些错误?下面是代码片段:
#include <QTextStream>
int main()
{
QTextStream out(stdout);
out << "console applicationn";
}
编译步骤如下:
qmake -project
qmake .pro file
make
按照上述步骤操作后,以下是我得到的输出:
g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o text.o text.cpp
text.cpp:1:23: error: QTextStream: No such file or directory
text.cpp: In function ‘int main()’:
text.cpp:5: error: ‘QTextStream’ was not declared in this scope
text.cpp:5: error: expected ‘;’ before ‘out’
text.cpp:6: error: ‘out’ was not declared in this scope
make: *** [text.o] Error 1
平台: Linux.
使用 qmake
和 make
而不是手动调用编译器。
cd YourProject/
qmake -project
qmake
make
./YourProjectTarget
并确保您调用的qmake
版本是 Qt4 版本,而不是 Qt3。您似乎安装了两个版本,并且您可能正在调用Qt3版本。
试试这个:
qmake -version
输出应该是这样的
QMake version 2.01a
Using Qt version 4.8.1 in /usr/lib/x86_64-linux-gnu
为了确保您调用的是正确的qmake
(Qt4),通常您可以将qmake
命令替换为 qmake-qtX
,其中X
是 Qt 版本。
cd YourProject/
qmake-qt4 -project
qmake-qt4
make
./YourProjectTarget
相关文章:
- luaL_dofile在已知良好的字节码上失败,可以使用未编译的版本
- 包含模板文件的递归会导致编译失败
- 提升 1.64 单元测试编译失败
- 如何让谷歌测试正常运行。测试总是失败。(它不会编译)
- 运行时检查失败 #0 用于运行时重新编译
- C++模板的模板编译失败
- 使用已删除的函数进行编译失败,并显示 uclibc
- MinGW-w64 编译失败,nullptr_t
- 使用提升线程时编译失败
- 编译花絮 g++, clang++, 使用 libboost -- g++8 编译失败时 g++7 成功;
- 编译成功,使用 clang 5.0.1/6.0.0 ,在 5.0.2/6.0.1 时失败
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- 带有引用的std::tuple在clang中编译失败,但在gcc中编译失败
- bitbake-grpc交叉编译/配置失败,错误为c-ares::care引用文件/usr/lib/libcares.s
- 解决由于在哈希函数中使用了不完整的类型而导致的编译失败
- 将XCode升级到verison 11.1后,C++编译失败
- 继承的构造函数,在 clang++3.9 中编译,在 g++ 7 中失败
- C++:此代码可以编译,但引发运行时检查失败 #2 - 围绕变量周围的堆栈'num'已损坏。发生
- 添加类型名会导致程序编译失败
- 将 qi::lexeme 添加到灵气中的规则时编译失败