前言

win10安装wsl中我们安装了Ubuntu,这时安装qt会报错

1
Full message -- "./gpt4all-0.1.0-Linux.run: error while loading shared libraries: libxcb-xinerama.so.0: cannot open shared object file: No such file or directory"

这时我们运行命令

1
sudo apt install libxcb-xinerama0 libxcb-cursor0

并没有任何作用,这时我通过安装gnome桌面解决了此问题。

安装gnome

开启systemd

由于gnome依赖systemd,所以我们应先安装systemd,在新版wsl2中已经支持了systemd,我们可以通过如下方式开启:

方法一:这里我安装之后遇到了其他问题,最后解决了,参考

方法二:

1
sudo nano /etc/wsl.conf

添加下述文本

1
2
[boot]
systemd=true

关闭wsl

1
wsl --shutdown

重新开启虚拟机,查看systemd状态

1
systemctl list-unit-files --type=service

安装gnome

直接进行安装可能报错,在这这之前我们需要进行一个操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Setting up acpi-support (0.144) ...
Failed to restart acpid.service: Transport endpoint is not connected
See system logs and 'systemctl status acpid.service' for details.
Failed to get properties: Transport endpoint is not connected

Setting up openvpn (2.5.5-1ubuntu3.1) ...
Failed to reload daemon: Transport endpoint is not connected
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on openvpn.service: No such file or directory

Setting up ubuntu-drivers-common (1:0.9.6.1) ...
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on gpu-manager.service: No such file or directory

Setting up whoopsie (0.2.77) ...
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on whoopsie.path: No such file or directory
Failed to reload daemon: Transport endpoint is not connected

Setting up power-profiles-daemon (0.10.1-3) ...
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on power-profiles-daemon.service: No such file or directory
Failed to reload daemon: Transport endpoint is not connected
Failed to get unit file state for power-profiles-daemon.service: Transport endpoint is not connected
Failed to retrieve unit state: Transport endpoint is not connected
power-profiles-daemon.service is a disabled or a static unit, not starting it.

Setting up upower (0.99.17-1) ...
Failed to reload daemon: Transport endpoint is not connected
Failed to get unit file state for upower.service: Transport endpoint is not connected
Failed to retrieve unit state: Transport endpoint is not connected
upower.service is a disabled or a static unit, not starting it.

Setting up secureboot-db (1.8) ...
Failed to preset unit: Transport endpoint is not connected
/usr/bin/deb-systemd-helper: error: systemctl preset failed on secureboot-db.service: No such file or directory
Failed to reload daemon: Transport endpoint is not connected

防止自动安装、升级或删除软件包

1
sudo apt-mark hold acpid acpi-support

安装gnome

1
sudo apt install ubuntu-desktop gnome

安装Qt

下载Qt

修改权限

1
sudo chmod +x ./qt*

运行

1
./qt*

换源安装

1
.\qt* --mirror https://mirrors.ustc.edu.cn/qtproject

报错

1
Full message -- "./gpt4all-0.1.0-Linux.run: error while loading shared libraries: libxcb-xinerama.so.0: cannot open shared object file: No such file or directory"

重新安装libxcb-cursor0

1
sudo apt install libxcb-xinerama0 libxcb-cursor0

再次运行,按照引导安装即可!

添加终端命令启动Qt

首先找到qt creator的可执行文件目录:

1
/home/james/Qt/Tools/QtCreator/bin

创建运行脚本

1
cd /usr/bin
1
sudo vim qtcreator

添加以下内容,记得替换地址,使用nohup命令来运行Qt Creator,并且将其与终端分离,使其不受终端关闭的影响。

1
2
3
#!/bin/sh
export QT_HOME=/home/james/Qt/Tools/QtCreator/bin
nohup $QT_HOME/qtcreator "$@" &

更改权限

1
chomd +x qtcreator

运行qtc+tab补齐

该封面图片由Kasjan FarbiszPixabay上发布