Ubuntu20.04安装Qt4.8.6环境(失败,改用Ubuntu14.04)

本博客记录了用Ubuntu20.04安装Qt4.8.6的过程,但在编译源码的时候失败了,且问题没有解决掉,最终不得不放弃,使用Ubuntu14.04的过程。

预备工作

Ubuntu更新源

在使用Ubuntu14.04等低版本时,由于软件源的问题,下载速度很慢,或者出现命令无法找到,需要更新源

参考这篇文章

博主使用Ubuntu14.04时,用阿里源解决了问题。

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

安装Qt

下载Qt4.8.6

下载页面:http://download.qt.io/archive/qt/4.8/4.8.6/

解压

tar -xvf qt-everywhere-opensource-src-4.8.6.tar 

编译

生成Makefile

  1. 到解压目录运行./configure,输入o,使用开源版本,提示"You don’t seem to have ‘make’ or ‘gmake’ in your PATH."。
root@pc-VirtualBox:/home/work/qt-everywhere-opensource-src-4.8.6# ./configure
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

You don't seem to have 'make' or 'gmake' in your PATH.

这篇文章看到了解决方法,需要安装g++编译器,需要安装build-essential:

sudo apt-get install build-essential 

重新执行./configure,输入o,再输入yes,

  1. 再次报错
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 /home/work/qt-everywhere-opensource-src-4.8.6/mkspecs/linux-g++.

进config.test / x11/xlib 执行make命令,看出错信息

cd config.tests/x11/xlib/
make

g++ -c -pipe -O2 -Wall -W  -I../../../mkspecs/linux-g++ -I. -I/usr/X11R6/include -o xlib.o xlib.cpp
xlib.cpp:42:10: fatal error: X11/Xlib.h: 没有那个文件或目录
   42 | #include <X11/Xlib.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:190:xlib.o] 错误 1

发现问题可能是X11没有安装,先安装X11

sudo apt-get install libx11-dev 

重新./configure,问题没有解决,可能是x11没有安装完整,运行apt-cache search x11-dev

sudo apt-cache search x11-dev
libx11-dev - X11 client-side library (development headers)
libxkbcommon-x11-dev - library to create keymaps with the XKB X11 protocol - development files
libghc-gi-gdkx11-dev - GDKX11 bindings
libghc-x11-dev - Haskell X11 binding for GHC
libnx-x11-dev - nxagent's libNX_X11 client-part library (development headers)
librust-cairo-sys-rs+x11-dev - FFI bindings to libcairo - feature "x11"
librust-x11-dev - X11 library bindings for Rust - Rust source code

安装X11相关的库,依次安装即可

sudo apt -get install libghc-x11-dev
sudo apt -get install libxkbcommon-x11-dev
sudo apt -get install libghc-gi-gdkx11-dev
sudo apt -get install libnx-x11-dev
sudo apt -get install librust-cairo-sys-rs+x11-dev
sudo apt -get install librust-x11-dev

再次运行./configure. Makefile生成成功

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

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

编译源代码

执行make

make

编译出错

dialogs/qprintdialog_unix.cpp:1020:40: error: ‘class Ui::QPrintWidget’ has no member named ‘printers’
 1020 |         printer->setPrinterName(widget.printers->currentText());
      |                                        ^~~~~~~~
make[1]: *** [Makefile:128933:.obj/release-shared/qprintdialog_unix.o] 错误 1
make[1]: 离开目录“/home/work/qt-everywhere-opensource-src-4.8.6/src/gui”
make: *** [Makefile:385:sub-gui-make_default-ordered] 错误 2

问题一直没有得到解决,最后无奈改装低版本的Ubuntu14.04,以下是Ubuntu14.04的教程。
有人说是因为虚拟机打印功能没有开启,导致这些问题,但我没找到解决办法。

相关资料:
求助,ubuntu 20 安装 qt 4.8.7 ,编译时的问题

尝试过./configure -no-cups,重新make,问题依然存在。

安装

执行make install

make install

创建软连接

root@VirtualBox:/home/work/qt-everywhere-opensource-src-4.8.6# qmake -v
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory

提示文件未找到,需要将/usr/local/Trolltech/Qt-4.8.6/bin/qmake连接起来

sudo ln -s /usr/local/Trolltech/Qt-4.8.6/bin/qmake /usr/bin/qmake

查看Qt版本

root@VirtualBox:/home/work/qt-everywhere-opensource-src-4.8.6# qmake -v

QMake version 2.01a
Using Qt version 4.8.6 in /usr/local/Trolltech/Qt-4.8.6/lib

测试HelloWorld

创建hello world

mkdir /home/qt/test
cd /home/qt/test
vim hello.cpp

添加内容

#include <QApplication>
#include <QLabel>

int main(int argc, char**argv)
{
	QApplication app(argc, argv);
	QLabel label("hello world!");

	label.show();
	return app.exec();	
}

生成工程

qmake -project
qmake -test.pro

编译

make

运行

./test

到这里就证明配置成功了。

参考文章

https://blog.youkuaiyun.com/wangyijieonline/article/details/105360138
https://blog.youkuaiyun.com/cuihongqiang/article/details/104350081
https://blog.youkuaiyun.com/Joker_Mr/article/details/78293498
https://blog.youkuaiyun.com/dongkai0918/article/details/101171741
https://blog.youkuaiyun.com/neu_sunlei/article/details/5524384
https://blog.youkuaiyun.com/anklean/article/details/58590833
https://blog.youkuaiyun.com/byxdaz/article/details/88881066

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值