You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Yocto构建Qt程序时Glib-2.0开发包未找到错误

解决Yocto构建Qt程序时glib-2.0开发包找不到的问题及GUI开机自启配置

一、修复glib-2.0开发包未找到错误

1. 检查并修改displaymod的Yocto Recipe(.bb文件)

  • 确保构建依赖中包含glib-2.0开发包,在recipe中添加:
    DEPENDS += "glib-2.0"
    inherit pkgconfig
    
    DEPENDS负责拉取构建时所需的开发文件,inherit pkgconfig确保Yocto正确配置pkg-config路径,让qmake能定位到glib的头文件和库。

2. 检查Qt项目的.pro文件

  • 确保.pro文件通过pkg-config链接glib-2.0,添加以下配置:
    CONFIG += link_pkgconfig
    PKGCONFIG += glib-2.0
    
    避免直接硬编码INCLUDEPATH和LIBS,Yocto构建环境下pkg-config会自动处理sysroot内的路径。

3. 清理缓存并重新构建

  • 执行以下命令清理旧构建状态,再重新构建:
    bitbake -c cleansstate displaymod
    bitbake displaymod
    

二、配置GUI程序开机自启

方法1:使用Systemd服务(推荐,适配Wayland/X11)

  1. 在displaymod的recipe目录下创建files/displaymod.service文件,内容如下:

    [Unit]
    Description=DisplayMod GUI Service
    After=graphical.target
    
    [Service]
    Type=simple
    ExecStart=/usr/bin/displaymod  # 替换为你的Qt程序实际安装路径
    Restart=always
    User=root
    
    [Install]
    WantedBy=graphical.target
    
  2. 在recipe中添加以下配置,让Yocto安装并启用该服务:

    SRC_URI += "file://displaymod.service"
    inherit systemd
    SYSTEMD_SERVICE:${PN} = "displaymod.service"
    SYSTEMD_AUTO_ENABLE:${PN} = "enable"
    

方法2:使用X11自动启动(仅适用于X11环境)

  1. 创建files/displaymod.desktop文件,内容如下:

    [Desktop Entry]
    Type=Application
    Name=DisplayMod
    Exec=/usr/bin/displaymod
    NoDisplay=false
    X-GNOME-Autostart-enabled=true
    
  2. 在recipe中添加配置,将.desktop文件安装到自动启动目录:

    SRC_URI += "file://displaymod.desktop"
    FILES:${PN} += "${datadir}/autostart/displaymod.desktop"
    

内容的提问来源于stack exchange,提问作者srivathsan official

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 21:58:23