目標是 Qt 4.8.4。從下載源碼到 Qt Creator 能正常啟動並編譯,中間的坑比想像中多,下面按順序記錄。
進入 https://download.qt-project.org/archive/qt/4.8/4.8.4/,下載的其實是 Qt 的庫代碼:
tar -xzf qt-everywhere-opensource-src-4.8.4.tar.gz
sudo apt-get install libX11-dev libXext-dev libXtst-dev sudo apt-get install libfontconfig1-dev # 字體庫,否則 ./configure -fontconfig 過不了
注意必須有 g++,否則 configure 會報錯:
cd qt-everywhere-opensource-src-4.8.4/ ./configure -fontconfig # 不加 -fontconfig 中文會顯示不出來
若指定嵌入式架構:
./configure -embedded x86
但這樣裝出來的版本無法開發 GUI 程式,需要 framebuffer 支援,所以想開發桌面程式應直接用 ./configure。
framebuffer 相關配置(實測仍不能開發 GUI):
接著選擇版本:
Which edition of Qt do you want to use? Type 'c' if you want to use the Commercial Edition. Type 'o' if you want to use the Open Source Edition.
選自由版輸入 o,同意許可協議輸入 yes,然後等配置跑完。
make # 或 make -j4 多線程編譯 sudo make install
安裝位置:直接 ./configure 時是 /usr/local/Trolltech/Qt-4.8.4;用 -embedded x86 則是 /usr/local/Trolltech/QtEmbedded-4.8.4/。
可以打包備份:
sudo zip -r QtEmbedded-4.8.4.zip ./QtEmbedded-4.8.4
但跨平台環境不能直接挪用,備份的實際價值有限。
下載:https://mirrors.ustc.edu.cn/qtproject/official_releases/qtcreator/(.run 檔),或舊版 https://download.qt-project.org/archive/qtcreator/2.5/ 的 qt-creator-linux-x86-opensource-2.5.2.bin。
chmod 777 qt-creator-linux-x86-opensource-2.8.1.run
雙擊運行安裝向導。注意必須在圖形界面下操作,控制台無法跑這個可視化向導。
若是 .bin 格式:
chmod 777 qt-creator-linux-x86-opensource-2.5.2.bin ./qt-creator-linux-x86-opensource-2.5.2.bin
按提示按 N 次 Enter,接受協議輸入 y。
若啟動報 libstdc++ 相關錯誤,見後面的錯誤處理。
新建一個 GUI 版本的 helloworld 直接運行。用 ./configure 安裝的可以正常跑:
但當初選了嵌入式參數的會報:
No Qt for Embedded Linux server appears to be running. If you want to run this program as a server, add the "-qws" command-line option.
非 GUI 程式則不受影響:
嵌入式 Qt 版本依賴 framebuffer 而非 X Window,而預設沒有編譯 framebuffer,需要手動編譯模擬器:
cd tools/qvfb/ make
結果報錯:
#error qvfb must be compiled with the Qt for X11 package
查資料後理清關係:Qt linux 版基於 X11;Qt embedded 版基於 framebuffer,不依賴 X11;而 qvfb 是 X11 平台的模擬器,用來模擬 Qt embedded 的運行流程,因此 qvfb 必須用 X11 版的 Qt 來編譯,同時你還需要一個 Qt-embedded 版本。參考:https://qt-project.org/doc/qt-4.7/qvfb.html
啟動報錯時,先查一下 libc 版本:
strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
可以看到沒有 3.4.15 版本,需要更新。直接 sudo apt-get install libstdc++6 不管用,得自己下載更新的版本:https://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/

由於有依賴問題,不能直接 sudo dpkg -i ****.deb,改為解壓後替換庫文件:
ar -x libstdc++6_4.7.2-5_i386.deb && tar xvf data.tar.gz
su cd usr/lib/i386-linux-gnu/
cp /home/fdr/soft_libs/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17 /usr/lib/ cd /usr/lib/ sudo mv libstdc++.so.6 libstdc++.so.6_____lfbc # 移開舊的軟鏈 ln -s libstdc++.so.6.17 libstdc++.so.6 sudo ldconfig # 少了這步系統認不出來,會報 cannot open shared object file
之後 Qt Creator 就能啟動了:
接著遇到:
libQtNetwork.so:-1: error: undefined reference to `__fdelt***********
原因是 Qt SDK 是在別台機器上編譯的,庫不一致,只能自己重新編譯 SDK。此時 make 又報:
/usr/bin/ld: cannot find -lXrender
到 /usr/lib 下查看:
確實名字不對,可以補一個軟鏈:
sudo ln -s libXrender.so.1.3.0 libXrender.so
但這裡真正的根因是兩次 configure 之間沒有 clean,導致 makefile 不正確。執行 make confclean,然後重新 configure、重新 make 即可。
libfontconfig1-dev : 依賴: libfontconfig1 (= 2.11.0-0ubuntu4) 但是 2.11.0-0ubuntu4.1 正要被安裝 依賴: libfreetype6-dev (>= 2.1.7) 但是它將不會被安裝 E: 無法修正錯誤,因為您要求某些軟件包保持現狀
解法是源裡的數據不夠完整,需要把搜狐或網易提供的源列表補齊,再重新 apt-get update 安裝。