Ubuntu 20.04下编译Minigui 5.0.11
代码下载和编译
在Ubuntu 20.04和22.04的版本上都试过,直接可以按照官网的步骤下载编译,一次性通过。
可是编译完之后,我却运行不了demo。
root@ubuntu:/home/number/code/build-minigui-5.0/cell-phone-ux-demo# ./mginit
NEWGAL>PCXVFB: Wait too long for CLIENT.
NEWGAL: Does not find matched engine: pc_xvfb.
Or failed to initialize the engine.
KERNEL>InitGUI (step 7): Can not get graphics engine information!
网上各种百度方法,修改Mingui.cfg,替换qvfb等等,我想这官方的demo,理论上不需要修改东西。
经了解,minigui5.0.11版本是默认使用gvfb来显示,我想着先用demo验证gtk显示是否正常。
编译GTK Demo
因为上述编译已经包含了gtk和gvfb,详情是./build-deps.sh。直接百度找了个gtk的代码
#include <gtk/gtk.h>
int main(int argc,char *argv[])
{
GtkWidget *window;
GtkWidget *label;
gtk_init(&argc,&argv);
/* create the main, top level, window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* give it the title */
gtk_window_set_title(GTK_WINDOW(window),"Hello World");
/* connect the destroy signal of the window to gtk_main_quit
* when the window is about to be destroyed we get a notification and
* stop the main GTK+ loop
*/
g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
/* create the "Hello, World" label */
label = gtk_label_new("Hello, World");
/* and insert it into the main window */
gtk_container_add(GTK_CONTAINER(window),label);
/* make sure that everything, window and label, are visible */
gtk_widget_show_all(window);
/* start the main loop, and let it rest until the application is closed */
gtk_main();
return 0;
}
编译成功,表示gtk是有的
root@ubuntu:/home# gcc test.c `pkg-config --cflags --libs gtk+-2.0`
In file included from /usr/include/gtk-2.0/gtk/gtkobject.h:37,
from /usr/include/gtk-2.0/gtk/gtkwidget.h:36,
from /usr/include/gtk-2.0/gtk/gtkcontainer.h:35,
from /usr/include/gtk-2.0/gtk/gtkbin.h:35,
from /usr/include/gtk-2.0/gtk/gtkwindow.h:36,
from /usr/include/gtk-2.0/gtk/gtkdialog.h:35,
from /usr/include/gtk-2.0/gtk/gtkaboutdialog.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:33,
from test.c:13:
/usr/include/gtk-2.0/gtk/gtktypeutils.h:236:1: warning: ‘GTypeDebugFlags’ is deprecated [-Wdeprecated-declarations]
236 | void gtk_type_init (GTypeDebugFlags debug_flags);
| ^~~~
In file included from /usr/include/glib-2.0/gobject/gobject.h:24,
from /usr/include/glib-2.0/gobject/gbinding.h:29,
from /usr/include/glib-2.0/glib-object.h:22,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-2.0/gdk/gdk.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from test.c:13:
/usr/include/glib-2.0/gobject/gtype.h:679:1: note: declared here
679 | {
| ^
In file included from /usr/include/gtk-2.0/gtk/gtktoolitem.h:31,
from /usr/include/gtk-2.0/gtk/gtktoolbutton.h:30,
from /usr/include/gtk-2.0/gtk/gtkmenutoolbutton.h:30,
from /usr/include/gtk-2.0/gtk/gtk.h:126,
from test.c:13:
/usr/include/gtk-2.0/gtk/gtktooltips.h:73:3: warning: ‘GTimeVal’ is deprecated: Use 'GDateTime' instead [-Wdeprecated-declarations]
73 | GTimeVal last_popdown;
| ^~~~~~~~
In file included from /usr/include/glib-2.0/glib/galloca.h:32,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/glib-2.0/gobject/gbinding.h:28,
from /usr/include/glib-2.0/glib-object.h:22,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-2.0/gdk/gdk.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from test.c:13:
/usr/include/glib-2.0/glib/gtypes.h:547:8: note: declared here
547 | struct _GTimeVal
| ^~~~~~~~~
root@ubuntu:/home# ls
a.out gtk gtk.c number test.c
执行却报错(意料之中)
root@ubuntu:/home# ./a.out
(a.out:208890): Gtk-WARNING **: 02:45:26.816: cannot open display:
百度原因,有的说增加环境变量
root@ubuntu:/home# export DISPLAY=:0
root@ubuntu:/home# ./a.out
No protocol specified
(a.out:208899): Gtk-WARNING **: 02:46:35.432: cannot open display: :0
不行,第二种方法:
root@ubuntu:/home# export DISPLAY=:0.0
root@ubuntu:/home# ./a.out
No protocol specified
(a.out:208900): Gtk-WARNING **: 02:47:35.737: cannot open display: :0.0
还是不行,然后问了一个幕后大神的回复
要解决这个问题,可以尝试以下步骤:
1、确认您已经以具有访问X显示权限的用户身份登录。
我用number账户登录的,然后切换的root
2、确认X服务器已经启动。在终端中输入 ps aux | grep X 命令进行确认。如果X服务器没有运行,请使用 startx 命令启动它。
number@ubuntu:~/code/build-minigui-5.0/mg-tests/compositor$ ps aux | grep X
number 3827 0.9 1.0 309960 40572 tty2 Sl+ 01:04 1:14 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3
number 209620 0.0 0.0 17540 716 pts/1 R+ 03:09 0:00 grep --color=auto X
看到这里我也不清楚有没有运行,还是执行一次startx
3、确认是否已经存在X授权文件。在终端中输入 ls -la /tmp/.X11-unix/ 命令进行确认。如果不存在,请使用 touch /tmp/.X11-unix/X0 命令创建一个,并使用 chmod 666 /tmp/.X11-unix/X0 设置其权限。
root@ubuntu:/home# ls -al /tmp/.X11-unix/
total 16
drwxrwxrwt 2 root root 4096 Apr 22 02:50 .
drwxrwxrwt 22 root root 12288 Apr 22 02:50 ..
srwxrwxrwx 1 number number 0 Apr 21 23:31 X0
srwxrwxr-x 1 gdm gdm 0 Apr 21 22:01 X1024
srwxrwxr-x 1 gdm gdm 0 Apr 21 22:01 X1025
这一步,我发现有个X0是属于number账户的,难道我需要切换回平台用户才能执行?
4、运行 export DISPLAY=:0.0 命令设置显示环境变量,然后再运行 xhost +。
我先切换回number账户,再执行一次这些命令
number@ubuntu:/home$ export DISPLAY=:0.0
number@ubuntu:/home$ xhost +
access control disabled, clients can connect from any host
number@ubuntu:/home$ ./a.out
Gtk-Message: 02:52:02.041: Failed to load module "canberra-gtk-module"
一步步排查后,最后运行demo,成功运行!!
最后试试minigui的demo
帅,可以执行
为什么root权限不能执行gtk呢?
重新尝试,切换root权限,重复一番操作
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests# xhost +
xhost: unable to open display ""
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests# export DISPLAY=:0.0
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests# xhost +
access control disabled, clients can connect from any host
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests# ls -al /tmp/.X11-unix/
total 16
drwxrwxrwt 2 root root 4096 Apr 22 02:58 .
drwxrwxrwt 22 root root 12288 Apr 22 03:14 ..
srwxrwxrwx 1 number number 0 Apr 21 23:31 X0
srwxrwxr-x 1 gdm gdm 0 Apr 21 22:01 X1024
srwxrwxr-x 1 gdm gdm 0 Apr 21 22:01 X1025
从这里看到还是没有root用户的文件
运行starx服务试试
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests/compositor# startx
X.Org X Server 1.20.13
X Protocol Version 11, Revision 0
Build Operating System: linux Ubuntu
Current Operating System: Linux ubuntu 5.15.0-69-generic #76~20.04.1-Ubuntu SMP Mon Mar 20 15:54:19 UTC 2023 x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-69-generic root=UUID=a225cebb-8a2f-46a2-8831-e3b072cf391a ro find_preseed=/preseed.cfg auto noprompt priority=critical locale=en_US quiet
Build Date: 07 February 2023 12:48:13PM
xorg-server 2:1.20.13-1ubuntu1~20.04.6 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.38.4
Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.1.log", Time: Sat Apr 22 03:20:58 2023
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
xinit: connection to X server lost
waiting for X server to shut down (II) Server terminated successfully (0). Closing log file.
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests/compositor#
能运行gtk的demo
但是跑minigui的demo就报错
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests/compositor# ./mginit helloworld
Gtk-Message: 03:49:01.085: Failed to load module "canberra-gtk-module"
NEWGAL>PCXVFB: failed to open tmp file
NEWGAL: Does not find matched engine: pc_xvfb.
Or failed to initialize the engine.
KERNEL>InitGUI (step 7): Can not get graphics engine information!
root@ubuntu:/home/number/code/build-minigui-5.0/mg-tests/compositor#
这里查看报错不一样,关于这个情况,应该就是minigui demo 的问题了。查了代码
然后ubuntu查看对应目录
红色这两个文件是原来的。原来之前运行minigui 的时候用了number用户,保存了这两个文件。我重命名这两个文件,然后再去
运行minigui的demo
OK!
运行cell-phone-ux-demo
number@number-virtual-machine:~/code/minigui5.x/build-minigui-5.0/cell-phone-ux-demo$ sudo ./mginit
not def win32
Gtk-Message: 20:34:39.135: Failed to load module "canberra-gtk-module"
load_font_data: failed to open the font file: font/Helvetica.ttf (1)
make_devfont: error when loading font ttf-helvetica-rrncnn-0-0-ISO8859-1,GB2312-0,UTF-8 from font/Helvetica.ttf file
load_font_data: failed to open the font file: /usr/local/share/minigui/res//font/Helvetica.ttf (1)
make_devfont: error when loading font ttf-helvetica-rrncnn-0-0-ISO8859-1,GB2312-0,UTF-8 from /usr/local/share/minigui/res//font/Helvetica.ttf file
mg_InitGDI: Can not initialize fonts defined in section truetypefonts!
KERNEL>InitGUI (step 8): Initialization of GDI resource failure!
遇事不要慌,这个问题就是找不到字库
umber@number-virtual-machine:~/code/minigui5.x/build-minigui-5.0/cell-phone-ux-demo$ find ./ -name Helvetica.ttf
./res/font/Helvetica.ttf
粗心的我,一开始以为字库存在,没问题。又去查了一下代码和百度了一下,原来路径不对。字库放在res目录了,代码里面是
去./font目录找,找不到再去/usr/local/share/minigui/res/目录。拷贝到对应目录
number@number-virtual-machine:~/code/minigui5.x/build-minigui-5.0/cell-phone-ux-demo$ sudo cp res/font/Helvetica.ttf /usr/local/share/minigui/res/font/
number@number-virtual-machine:~/code/minigui5.x/build-minigui-5.0/cell-phone-ux-demo$ sudo ./mginit
not def win32
Gtk-Message: 20:35:21.954: Failed to load module "canberra-gtk-module"
load_font_data: failed to open the font file: font/Helvetica.ttf (1)
make_devfont: error when loading font ttf-helvetica-rrncnn-0-0-ISO8859-1,GB2312-0,UTF-8 from font/Helvetica.ttf file
(pcxvfb:196808): IBUS-WARNING **: 20:35:21.981: Failed to mkdir /root/.config/ibus/bus: Permission denied
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
new child, pid: 196816.
not def win32
ClientRequestEx2: Received an invalid file descriptor.
load_font_data: failed to open the font file: font/Helvetica.ttf (1)
make_devfont: error when loading font ttf-helvetica-rrncnn-0-0-ISO8859-1,GB2312-0,UTF-8 from font/Helvetica.ttf file
InitVectorialFonts: deprecated
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
...
到此总算可以看到UI了。其实上面就一个问题,那个gtk不能用其他用户显示,我习惯性的开机打开shell,然后就切换root用户,
操作为所欲为。如果需要root用户下也能显示界面,需要先在Ubuntu开机登录的那个用户在shell里面,执行xhost +授权,才能切
换root用户操作。
完结!希望能帮到你。