- C/C++ code
---------------------------------------------------# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programs#新增qtQTDIR=/usr/local/Trolltech/Qt-4.7.3MANPATH=$QTDIR/doc/man:$MANPATHLD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATHQMAKESPEC=$QTDIR/mkspecs/linux-g++:$QMAKESPECQt_include_QtGui=$QTDIR/include/QtGui:$Qt_include_QtGui:$Qt_include_QtGuiPATH=$HOME/bin:$QTDIR/bin:QMAKESPEC:$PATHexport QTDIR PATH MANPATHLD_LIBRARY_PATH Qt_include_QtGui-------------------------[root@man hello]# qmake -project[root@man hello]# qmake hello.pro[root@man hello]# make >error.txt 2>&1前面两个命令都没错,就是make的时候报错:--------------------------------------gcc -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.7.3/mkspecs/linux-g++-64 -I. -I/usr/local/Trolltech/Qt-4.7.3/include/QtCore -I/usr/local/Trolltech/Qt-4.7.3/include/QtGui -I/usr/local/Trolltech/Qt-4.7.3/include -I. -I. -o hello.o hello.cIn file included from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobjectdefs.h:45, from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobject.h:47, from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qcoreapplication.h:45, from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qapplication.h:45, from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QApplication:1, from hello.c:1:/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h:54: 警告:返回类型默认为‘int’/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h: 在函数‘QT_MODULE’中:/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h:54: 错误:expected declaration specifiers before ‘namespace’/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h:1787: 错误:expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h:1808: 错误:expected declaration specifiers before ‘class’/usr/local/Trolltech/Qt-4.7.3/include/QtCore/qnamespace.h:1863: 错误:expected declaration specifiers before ‘;’ tokenIn file included from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qobject.h:47, from /usr/local/Trolltech/Qt-4.7.3/include/QtCore/qcoreapplication.h:45, from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/qapplication.h:45, from /usr/local/Trolltech/Qt-4.7.3/include/QtGui/QApplication:1......--------------------------------------------------#include<QApplication>#include<QLabel>int main(int arg, char *argv[]){ QApplication app(arg,argv); QLabel *label = new QLabel("HELLO QT !"); label -> show(); return app.exec();}程序在windowsQt编译正常通过
------解决方案--------------------
扩展名 改成 cpp
------解决方案--------------------
qt 程序是c++的, 编译的时候使用g++而不是gcc