qt 编译问题总结

1)使用make命令编译Qt原码时出现了 /usr/bin/ld: cannot find -lXrender 问题:html

        /usr/bin/ld: cannot find -lXrender
        collect2: ld 返回 1
        make[1]: *** [../../../../lib/libQtWebKit.so.4.7.4] 错误 1
        make[1]:正在离开目录 `/home/Qt/qt-everywhere-opensource-src-4.7.4/src/3rdparty/webkit/WebCore'
        make: *** [sub-webkit-make_default-ordered] 错误 2python

 

其解决方法以下:linux

执行sudo apt-get install libXrender-dev命令,安装相应的lib文件。web

 

因此最好在编译Qt原码前先执行如下命令:sql

        sudo apt-get install libglib2.0-dev libSM-dev libxrender-dev libfontconfig1-dev libxext-devubuntu

        sudo apt-get install libglui-dev小程序

安装相应的lib文件,防止编译出错。缓存

 

再上网搜索一下,发如今Linux下编译应用程序经常会出现以下错误:
/usr/bin/ld:cannot find -lxxx
意思是编译过程找不到对应库文件。其中-lxxx表示连接库文件libxxx.so。架构


通常出现这种错误有如下几种缘由:
1.系统缺少对应的库文件
2.库文件版本不对应
3.库文件连接错误
4.库文件路径设置不正确app


对于前2种状况,能够经过下载安装lib来解决:
sudo apt-get install libxxx-dev(上面编译Qt的状况大可能是这样)


而对于第3种状况,经过find或者locate命令定位到连接文件,查看连接文件是否正确的指向了lib文件。若是不是,用 ln -sf */libxxx.so.x */libxxx.so 命令修改。


对于最后一种状况,能够到/etc/ld.so.conf.d目录下,修改其中任意一份conf文件(也可自建conf),将lib所在的目录写进去,而后在终端输入ldconfig更新缓存。

 

2) 如下博客来自

Andysun1986http://blog.csdn.net/andysun1986/article/details/6308838

 

去年春天我用Qt3写了一个小软件,感受Linux下用Qt做界面程序很方便,和Windows下的VC差很少. 因此上次ubuntu 7.10系统一安装好就将Qt3开发包安装上去。这儿顺便把之前安装Qt3软件包貼出来。

#sudo apt-get install qt3-dev-tools qt3-examples Python-qt3 qt3-designer qt3-assistant

如今Qt 的版本已经到Qt-4.3.2了,最近打算用Qt4写个小程序。网上找到安装以下软件包:

#sudo apt-get install qt4-dev-tools qt3-examples qt4-designer qt3-assistant python-qt4

这 里面qt3-examples qt3-assistant,由于相应的qt4版本apt-get找不到,因此就安装了之前的版本. 下面写一个Qt4 的hello world, 来源于 C++ GUI Programming with Qt 4的第一个程序,以下:

#include
#include
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}

能够发现这个简单的hello world和Qt3就有一些变化了。

下面编译程序:
#qmake -project
生成配置文件xxx.pro(其中xxx为工程文件名)
#qmake
自动生成Makefile文件
#make
出现了下面的错误信息:
me.cpp:1:28: 错误: qt4/QApplication:No such file or directory
me.cpp:2:22: 错误: qt4/QLabel:No such file or directory
me.cpp: In function ‘int main(int, char**)’:
me.cpp:5: 错误: ‘QApplication’ 在此做用域中还没有声明
me.cpp:5: 错误: expected `;' before ‘app’
me.cpp:6: 错误: ‘QLabel’ 在此做用域中还没有声明
me.cpp:6: 错误: ‘label’ 在此做用域中还没有声明
me.cpp:6: 错误: expected type-specifier before ‘QLabel’
me.cpp:6: 错误: expected `;' before ‘QLabel’
me.cpp:8: 错误: ‘app’ 在此做用域中还没有声明
me.cpp: At global scope:
me.cpp:3: 警告: 未使用的参数 ‘argc’
me.cpp:3: 警告: 未使用的参数 ‘argv’
make: *** [me.o] 错误 1

打开Makefile文件, 发现里面包含的Qt文件所有是和 Qt3有关的,使用qmake -v 命令发现果真qmake的版本是3,whereis找到qmake命令所在目录/usr/bin/qmake

#ls -l qmake*
lrwxrwxrwx 1 root root 23 2008-01-18 20:53 /usr/bin/qmake -> /etc/alternatives/qmake
-rwxr-xr-x 1 root root 2052100 2007-10-31 01:29 /usr/bin/qmake-qt3
-rwxr-xr-x 1 root root 3378140 2007-11-06 07:56 /usr/bin/qmake-qt4
# ls -l /etc/alternatives/qmake
lrwxrwxrwx 1 root root 18 2008-01-18 20:56 /etc/alternatives/qmake -> /usr/bin/qmake-qt3

如今清楚了 qmake是个连接,经过alternatives/qmake指向qmake-qt3,如今想让qmake默认为qmake-qt4,只要重定向连接
#sudo rm /etc/alternatives/qmake
#sudo ln -s /usr/bin/qmake-qt4 /etc/alternatives/qmake
一样,想要designer命令默认是版本4,只要
#sudo rm /etc/alternatives/designer
#sudo ln -s /usr/bin/designer-qt4 /etc/alternatives/designer

如今好了,再次qmake -project , qmake, make 上面的hello world文件,一切顺利。

 

3)如下博客来自  http://www.cnitblog.com/zouzheng/archive/2010/07/06/67197.html

 在交叉编译过程当中,在./configure中加上相似-qt-mouse-*和-qt-kbd-*就会出现unknown argument错误。

 ./configure
-prefix /usr/local/qte-arm    (强制安装在此路径)
-debug-and-release             编译和连接两个版本的Qt
-qt3support                    支持QT3
-qt-zlib                       捆绑使用的Qt的zlib。
-qt-libtiff                    使用Qt的捆绑的libtiff。
-qt-libpng                     使用Qt的捆绑的的libpng。
-qt-libmng                     使用Qt的捆绑的libmng。
-qt-libjpeg                    使用Qt的捆绑的的libjpeg。
-make libs                     新增 libs
-nomake examples               排除 。。
-nomake demos                  排除。。
-nomake docs                   排除。。
-no-cups                       不要编译CUPS的支
-iconv                         编译iconv拥有支持(3)
-xplatform qws/linux-arm-g++  
-embedded arm                       
-little-endian
-qt-freetype
-depths 8,16,24,32
-qt-gfx-linuxfb
-no-gfx-transformed
-no-gfx-qvfb
-no-gfx-vnc
-no-gfx-multiscreen
-no-dbus
-qt-sql-sqlite
-qt-kbd-qvfb
-qt-kbd-tty
-qt-mouse-pc
-no-glib
-plugin-mouse-tslib -I/usr/local/tslib/ -L/usr/local/tslib/lib -D__ARM_ARCH_5TEJ__
                       (包含路径)                                 (库路径)                     (定义的预处理器)

 

以mipsel为架构的loongson1B开发板在交叉编译QT4.5以上版本时的配置为:

 

[cpp]  view plain  copy
 在CODE上查看代码片派生到个人代码片
  1. ./configure -prefix /opt/qt4-mipsel -release -shared -fast -pch -no-qt3support -qt-sql-sqlite -no-libtiff -no-libmng -qt-libjpeg -qt-zlib -qt-libpng -qt-freetype -no-openssl -no-webkit -nomake examples -nomake demos -nomake tools -optimized-qmake -no-phonon -no-nis -no-opengl -no-cups -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xkb -no-sm -no-xinerama -no-xshape -no-separate-debug-info -xplatform qws/linux-mips-g++ -embedded mips -little-endian -depths 16 -no-qvfb -qt-gfx-linuxfb -no-gfx-qvfb -no-kbd-qvfb -no-mouse-qvfb -confirm-license -qt-mouse-tslib -I/opt/tslib-mipsel/include -L/opt/tslib-mipsel/lib    

 

 

 

若是出错:
/usr/local/arm/4.1.2/bin/../lib/gcc/arm-angstrom-linux-gnueabi/4.1.2/../../../../arm-angstrom-linux-gnueabi/bin/ld: warning: libts-0.0.so.0, needed by /home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so, not found (try using -rpath or -rpath-link)
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_read_raw'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_open'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_fd'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_config'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_close'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_read'
collect2: ld returned 1 exit status
make[2]: *** [deform] Error 1
make[2]: Leaving directory `/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/demos/deform'
make[1]: *** [sub-deform-make_default] Error 2
make[1]: Leaving directory `/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/demos'
make: *** [sub-demos-make_default-ordered] Error 2

解决办法:
修改qt-4.6.1/mkspecs/qws/linux-mips-g++/qmake.conf 文件(添加lts参数):
QMAKE_CC                = mips-linux-gcc -lts
QMAKE_CXX               = mips-linux-g++ -lts
QMAKE_LINK              = mips-linux-g++ -lts
QMAKE_LINK_SHLIB        = mips-linux-g++ -lts

#sudo make install

 

4) 

mipsel-linux-g++ -Wl,-rpath-link,/opt/qt-everywhere-opensource-src-4.8.6/lib -fno-exceptions -Wl,-O1 -Wl,-rpath,/opt/qt-everywhere-opensource-src-4.8.6/src/3rdparty/webkit/Source/lib -Wl,-rpath,/opt/qt4-mipsel/lib -Wl,-rpath,/opt/qt4-mipsel/lib -o tst_qwebframe .obj/release-shared-emb-mips/tst_qwebframe.o .obj/release-shared-emb-mips/qrc_tst_qwebframe.o    -L/TSLIB/lib -L/opt/qt-everywhere-opensource-src-4.8.6/lib -L/TSLIB/lib -L/opt/qt-everywhere-opensource-src-4.8.6/lib -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lQtWebKit -lQtTest -lQtGui -lQtNetwork -lQtCore -lpthread /opt/gcc-4.3-ls232-softfloat/lib/gcc/mipsel-linux/4.3.0/../../../../mipsel-linux/bin/ld: warning: libts-0.0.so.0, needed by /opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so, not found (try using -rpath or -rpath-link)/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_read_raw'/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_open'/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_fd'/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_config'/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_close'/opt/qt-everywhere-opensource-src-4.8.6/lib/libQtGui.so: undefined reference to `ts_read'collect2: ld returned 1 exit statusMakefile.WebKit:109: recipe for target 'tst_qwebframe' failedmake[3]: *** [tst_qwebframe] Error 1make[3]: Leaving directory '/opt/qt-everywhere-opensource-src-4.8.6/src/3rdparty/webkit/Source/WebKit/qt/tests/qwebframe'Makefile.WebKit:51: recipe for target 'sub-qwebframe-make_default' failedmake[2]: *** [sub-qwebframe-make_default] Error 2make[2]: Leaving directory '/opt/qt-everywhere-opensource-src-4.8.6/src/3rdparty/webkit/Source/WebKit/qt/tests'Makefile.WebKit:187: recipe for target 'sub-WebKit-qt-tests-make_default-ordered' failedmake[1]: *** [sub-WebKit-qt-tests-make_default-ordered] Error 2make[1]: Leaving directory '/opt/qt-everywhere-opensource-src-4.8.6/src/3rdparty/webkit/Source'Makefile:562: recipe for target 'sub-webkit-make_default-ordered' failedmake: *** [sub-webkit-make_default-ordered] Error 2eb http://ppa.launchpad.net///deb.opera.com/opera-stable/ stable non-free/ubuntu maverick main解决办法:修改qt-everywhere-opensource-src-4.6.0/mkspecs/qws/linux-mips-g++/qmake.conf 文件(添加lts参数):QMAKE_CC = mipsel-linux-gcc -ltsQMAKE_CXX = mipsel-linux-g++ -ltsQMAKE_LINK = mipsel-linux-g++ -ltsQMAKE_LINK_SHLIB = mipsel-linux-g++ -lts

相关文章
相关标签/搜索