zoukankan      html  css  js  c++  java
  • qt 编译问题总结

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

            /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] 错误 2

    其解决方法如下:

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

    所以最好在编译Qt原码前先执行以下命令:

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

            sudo apt-get install libglui-dev

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

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


    一般出现这种错误有以下几种原因:
    1.系统缺乏对应的库文件
    2.库文件版本不对应
    3.库文件链接错误
    4.库文件路径设置不正确


    对于前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 status
    Makefile.WebKit:109: recipe for target 'tst_qwebframe' failed
    make[3]: *** [tst_qwebframe] Error 1
    make[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' failed
    make[2]: *** [sub-qwebframe-make_default] Error 2
    make[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' failed
    make[1]: *** [sub-WebKit-qt-tests-make_default-ordered] Error 2
    make[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' failed
    make: *** [sub-webkit-make_default-ordered] Error 2
    eb 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 -lts
    QMAKE_CXX = mipsel-linux-g++ -lts
    QMAKE_LINK = mipsel-linux-g++ -lts
    QMAKE_LINK_SHLIB = mipsel-linux-g++ -lts

  • 相关阅读:
    第6周编程题:零基础学Java
    帆软报表软件学习计划
    北大软件工程——第八周:面向对象设计2
    hdu1264 Counting Squares
    hdu1264 Counting Squares
    poj1151 Atlantis(线段树+扫描线)
    poj1151 Atlantis(线段树+扫描线)
    bzoj4653 [Noi2016]区间
    bzoj4653 [Noi2016]区间
    Tyvj1043
  • 原文地址:https://www.cnblogs.com/daocaoren/p/6151823.html
Copyright © 2011-2022 走看看