0%

Ubuntu20.10编译安装Qt4.8.7_ubuntu22.04安装qt4.8.7-CSDN博客

Excerpt

文章浏览阅读3.6k次,点赞4次,收藏26次。Ubuntu20.10编译安装Qt4.8.7安装低版本的gcc首先要安装低版本的gcc,高版本的编译时会报各种错误。这里选的是gcc-4.8。由于这个版本的gcc太老旧,安装过程有点曲折。加入并更新下载源(否则在sudo时可能找不到4.8版本)sudo gedit /etc/apt/sources.list在sources.list文件的最下面添加如下代码deb http://dk.archive.ubuntu.com/ubuntu/ xenial main_ubuntu22.04安装qt4.8.7


Ubuntu20.10编译安装Qt4.8.7

安装低版本的gcc

首先要安装低版本的gcc,高版本的编译时会报各种错误。这里选的是gcc-4.8。

由于这个版本的gcc太老旧,安装过程有点曲折。

  1. 加入并更新下载源(否则在sudo时可能找不到4.8版本)
1
sudo gedit /etc/apt/sources.list
  1. 在sources.list文件的最下面添加如下代码
1
2
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe
  1. 更新源
1
sudo apt-get update

可能出现的错误 若是在update时,出现如下错误

1
The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32

这是系统不包含该公钥导致,输入以下指令

1
2
3
4
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <PUBKEY>
//其中 <PUBKEY>更换为上面错误提示中出现的公钥,如:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32

然后重新执行:sudo apt-get update

  1. 安装gcc、g++(以4.8为例)
1
2
sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8

注意:在输入指令sudo apt-get install gcc之后,连按两下tab键,可以查看全部能安装的gcc版本

将其添加到可选版本列表中:

1
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.8

切换默认的gcc版本,使用以下update-alternatives命令:

1
2
3
4
5
6
7
8
9
10
11
12
sudo update-alternatives --config gcc
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).

Selection   Path             Priority   Status
------------------------------------------------------------
0           /usr/bin/gcc-10   100       auto mode
1           /usr/bin/gcc-10   100       manual mode
2           /usr/bin/gcc-4.8   40       manual mode
* 3           /usr/bin/gcc-9     90       manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in manual mode

系统将为您提供Ubuntu系统上所有已安装的GCC版本的列表。输入您要用作默认版本的版本号,然后按Enter

该命令将创建指向gcc和g++特定版本的符号链接。

确认当前gcc的版本号:

1
2
3
4
5
gcc --version
gcc (Ubuntu 4.8.5-4ubuntu2) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编译安装Qt4.8.7

解压并配置

1
2
3
tar xf qt-everywhere-opensource-src-4.8.7.tar.gz
cd qt-everywhere-opensource-src-4.8.7/
./configure -opensource -no-openssl -no-sql-mysql

注意:可以使用 make confclean 命令把以前的配置信息清除掉,然后再重新配置。

configure过程中报错:

1
2
3
Basic XLib functionality test failed!
You might need to modify the include and library search paths by editing
QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11 in /opt/qt-everywhere-opensource-src-4.8.7/mkspecs/linux-g++.

这个错误主要是因为XLib库没有安装,因此执行:

1
sudo apt-get install libx11-dev libxext-dev libxtst-dev

再次configure执行成功,出现提示:

1
2
3
4
5
6
7
WARNING: DESTDIR: Cannot access directory '/usr/local/Trolltech/Qt-4.8.7/plugins/webkit'

Qt is now configured for building. Just run 'gmake'.
Once everything is built, you must run 'gmake install'.
Qt will be installed into /usr/local/Trolltech/Qt-4.8.7

To reconfigure, run 'gmake confclean' and 'configure'.

现在可以编译并安装了:

1
2
make -j8
sudo make install

解决字体问题

按照上面的步骤安装Qt,之后编译并运行应用程序,发现程序的字体模糊难看,而且不能显示中文。

因此需要安装相关依赖,并加入配置选项fontconfig,如下:

1
2
3
4
5
sudo apt-get install libfreetype6-dev 
sudo ln -s /usr/include/freetype2/freetype/ /usr/include/freetype
sudo apt-get install libfontconfig1-dev

./configure -opensource -no-openssl -no-sql-mysql -fontconfig

之后编译并安装Qt,重新编译应用程序,发现中文也能优美显示了。

参考资料

Ubuntu 下 Tiny6410 嵌入式 Qt 开发环境的搭建

如何在Ubuntu 20.04上安装GCC

Ubuntu 19.10 降级安装gcc4.8、g++4.8

Linux/ubuntu下编译安装QT 4.8 (QT 4.8.4)