qt 編譯問題總結

以下博客來自makuiyu: http://blog.csdn.net/makuiyu/article/details/7017368


   

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以上版本時的配置爲:

./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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章