Welcome 微信登录

首页 / 操作系统 / Linux / Fedora 5安装Qt4后qmake自动连接至Qt3的解决办法

在Fedora上的安装Qt4,我一开始就用了root用户,与Ubuntu差别很小。
#mv qt-everywhere-opensource-src-4.6.2.tar.gz /tmp
#cd /tmp
#gunzip qt-everywhere-opensource-src-4.6.2.tar.gz
#tar xvf qt-everywhere-opensource-src-4.6.2.tar
#cd qt-everywhere-opensource-src-4.6.2
#./configure
#gmake   (注意此处是gmake)
#gmake install
环境变量设置略。按照前文中的步骤在Fedora 5上安装完Qt4.6.2后,设置好环境变量,www.linuxidc.com用qmake编译程序hello.cpp,程序代码如下(C++ GUI Programming With Qt 4的第一个程序):#include <QApplication>#include <QLabel>int main(int argc, char *argv[]){    QApplication app(argc, argv);    QLabel *label = new QLabel("Hello Qt!");    label->show();    return app.exec();}$qmake -project$qmake hello.pro$make然后出现错误:hello.cpp:1:24: error: QApplication: No such file or directory
hello.cpp:2:18: error: QLabel: No such file or directory
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:6: error: ‘QApplication’ was not declared in this scope
hello.cpp:6: error: expected `;" before ‘app’
hello.cpp:7: error: ‘QLabel’ was not declared in this scope
hello.cpp:7: error: ‘label’ was not declared in this scope
hello.cpp:7: error: expected type-specifier before ‘QLabel’
hello.cpp:7: error: expected `;" before ‘QLabel’
hello.cpp:9: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:4: warning: unused parameter ‘argc’
hello.cpp:4: warning: unused parameter ‘argv’
make: *** [hello.o] Error 1通过分析得知无法找到头文件,从而下面的都出错。于是猜想系统默认的qmake是Qt3中的程序。使用全路径编译如下:$ /usr/local/Trolltech/Qt-4.6.2/bin/qmake -project$ /usr/local/Trolltech/Qt-4.6.2/bin/qmake hello.pro$makeg++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.6.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.6.2/include/QtCore -I/usr/local/Trolltech/Qt-4.6.2/include/QtGui -I/usr/local/Trolltech/Qt-4.6.2/include -I. -I. -o hello.o hello.cpp
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/Qt-4.6.2/lib -o hello hello.o    -L/usr/local/Trolltech/Qt-4.6.2/lib -lQtGui -L/usr/local/Trolltech/Qt-4.6.2/lib -L/usr/X11R6/lib -lQtCore -lpthread$lshello hello.cpp hello.o hello.pro Makefile出现了可执行程序hello,编译成功,运行也成功,于是断定,默认的qmake不是我们需要的/usr/local/Trolltech/Qt-4.6.2/bin/qmake。下面我们来定位以下系统中有多少个qmake程序:
$locate qmake/usr/bin/qmake
/usr/include/kdevelop/buildtools/parsers/qmake/usr/lib/qt-3.3/bin/qmake/usr/local/Trolltech/Qt-4.6.2/bin/qmake只列出部分我们需要的,好了,可以看到有qt-3.3的qmake混迹其中,而/usr/bin在环境变量中,可能第一个/usr/bin/qmake就是我们运行出错的qmake。我们来研究一下/usr/bin/qmake:$which qmake/usr/bin/qmake可以看到这个就是默认的qmake$ls -l /usr/bin/qmakerwxrwxrwx 1 root root 23 Mar 23 12:59 /usr/bin/qmake -> ../lib/qt-3.3/bin/qmake$ file /usr/bin/qmake
/usr/bin/qmake: symbolic link to `../lib/qt-3.3/bin/qmake"明白了吧,这个是qt-3.3中qmake的一个软链接。只要修改一下它指向的位置就可以了。$suPassword:#ln -s /usr/local/Trolltech/Qt-4.6.2/bin/qmake /usr/bin/qmake
ln: creating symbolic link `/usr/bin/qmake" to `/usr/local/Trolltech/Qt-4.6.2/bin/qmake": File exists#ln -s /usr/local/Trolltech/Qt-4.6.2/bin/qmake /usr/bin/qmake1#ls /usr/bin/qmak*/usr/bin/qmake  /usr/bin/qmake1# mv /usr/bin/qmake1 /usr/bin/qmake
mv: overwrite `/usr/bin/qmake"?yes# ls /usr/bin/qmak*
/usr/bin/qmake#ls -al /usr/bin/qmake
lrwxrwxrwx 1 root root 39 Mar 25 16:18 /usr/bin/qmake -> /usr/local/Trolltech/Qt-4.6.2/bin/qmake成功了,下面删除刚才的Makefile,重新编译:$ qmake -project
QFileInfo::absolutePath: Constructed with empty filename
$ qmake hello.pro
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.6.2/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.6.2/include/QtCore -I/usr/local/Trolltech/Qt-4.6.2/include/QtGui -I/usr/local/Trolltech/Qt-4.6.2/include -I. -I. -o hello.o hello.cpp
g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/Qt-4.6.2/lib -o hello hello.o    -L/usr/local/Trolltech/Qt-4.6.2/lib -lQtGui -L/usr/local/Trolltech/Qt-4.6.2/lib -L/usr/X11R6/lib -lQtCore -lpthread
$ ls
hello  hello.cpp  hello.o  hello.pro  Makefile问题解决。Ubuntu下为Rhythmbox提供豆瓣电台插件在Ubuntu下使用TAP网卡相关资讯      Qt  Fedora教程 
  • QT 的信号与槽机制介绍  (04月07日)
  • Qt实现文件拆分和融合小工具  (01月08日)
  • Qt入门学习——Qt 5 帮助文档的使  (09/16/2015 08:32:11)
  • Qt不再使用LGPLv2.1授权  (01月14日)
  • 如何在 Ubuntu 中安装 QGit 客户端  (09/26/2015 10:10:09)
  • 在调用Qt库来实现功能过程中的一些  (08/30/2015 08:42:17)
本文评论 查看全部评论 (0)
表情: 姓名: 字数