移植dbus遇到的坑

dbus总线主要用于进程间通讯,Linux里面是用的很成熟,但很多人没有用过可能很陌生。

dbus主页https://www.freedesktop.org/   

1.下载dbus源码

https://www.freedesktop.org/wiki/Software/dbus/#sourcecode

The current stable branch is dbus 1.14.x. This is the recommended version for most purposes.
意思是稳定版1.14.x
下载了dbus-1.14.10.tar.xz

解压

tar -xvf dbus-1.14.10.tar.xz 

2.编译错误(1)    No package 'expat' found

编译
我的交叉编译工具是

./configure --prefix=/root/share/app/dbus/dbus_install --host=arm-nuvoton-linux-gnueabi CC=/root/share/nuvoton_cross/host/usr/bin/arm-nuvoton-linux-gnueabi-gcc --with-xml=libxml  

编译错误

checking for expat... no
configure: error: Package requirements (expat) were not met:

No package 'expat' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables EXPAT_CFLAGS
and EXPAT_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
root@ubuntu:~/share/app/dbus/dbus-1.14.10# 

需要安装expat

Expat是一个用C语言开发的、用来解析XML文档的开发库,它最初是开源的、Mozilla 项目下的一个XML解析器。

https://github.com/libexpat/libexpat/releases
下载源码 进入解压目录执行 ./configure


mkdir -p /root/share/gateway/app/openlib/expat_install
./configure --prefix=/root/share/gateway/app/openlib/expat_install --host=arm-nuvoton-linux-gnueabi CC=/root/share/nuvoton_cross/host/usr/bin/arm-nuvoton-linux-gnueabi-gcc

make 

make install

root@ubuntu:~/share/gateway/app/openlib/expat_install# tree
.
├── bin
│   └── xmlwf
├── include
│   ├── expat_config.h
│   ├── expat_external.h
│   └── expat.h
├── lib
│   ├── cmake
│   │   └── expat-2.6.2
│   │       ├── expat.cmake
│   │       ├── expat-config.cmake
│   │       ├── expat-config-version.cmake
│   │       └── expat-noconfig.cmake
│   ├── libexpat.a
│   ├── libexpat.la
│   ├── libexpat.so -> libexpat.so.1.9.2
│   ├── libexpat.so.1 -> libexpat.so.1.9.2
│   ├── libexpat.so.1.9.2
│   └── pkgconfig
│       └──   
└── share
    ├── doc
    │   └── expat
    │       ├── AUTHORS
    │       └── changelog
    └── man
        └── man1 r
            └── xmlwf.1

11 directories, 17 files
root@ubuntu:~/share/gateway/app/openlib/expat_install# 

需要拷贝到对应编译工具链目录

cp /root/share/gateway/app/openlib/expat_install/include/* /root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot/usr/include/ -arf 
cp /root/share/gateway/app/openlib/expat_install/lib/libexpat* /root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot/usr/lib/ -arf 
cp /root/share/gateway/app/openlib/expat_install/lib/pkgconfig/* /root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot/usr/lib/pkgconfig -arf

再编译,还是提示没有找到expat

终极解决方法:设置PKG_CONFIG_LIBDIR,PKG_CONFIG_SYSROOT_DIR,不然dbus编译找不到expat

 export PKG_CONFIG_LIBDIR=/root/share/nuvoton_cross/host/usr/lib/pkgconfig:/root/share/nuvoton_cross/host/usr/share/pkgconfig:$PKG_CONFIG_LIBDIR

 export  PKG_CONFIG_SYSROOT_DIR=/root/share/nuvoton-build-rootfs/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-gnueabi/sysroot:/root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot:$PKG_CONFIG_SYSROOT_DIR
执行
  ./configure --prefix=/root/share/gateway/app/dbus/dbus_install --host=arm-nuvoton-linux-gnueabi CC=/root/share/nuvoton_cross/host/usr/bin/arm-nuvoton-linux-gnueabi-gcc --with-xml=libxml 

执行
make 

执行

make install

root@ubuntu:~/share/gateway/app/dbus/dbus_install# tree
.
├── bin
│   ├── dbus-cleanup-sockets
│   ├── dbus-daemon
│   ├── dbus-launch
│   ├── dbus-monitor
│   ├── dbus-run-session
│   ├── dbus-send
│   ├── dbus-test-tool
│   ├── dbus-update-activation-environment
│   └── dbus-uuidgen
├── etc
│   └── dbus-1
│       ├── session.conf
│       └── system.conf
├── include
│   └── dbus-1.0
│       └── dbus
│           ├── dbus-address.h
│           ├── dbus-bus.h
│           ├── dbus-connection.h
│           ├── dbus-errors.h
│           ├── dbus.h
│           ├── dbus-macros.h
│           ├── dbus-memory.h
│           ├── dbus-message.h
│           ├── dbus-misc.h
│           ├── dbus-pending-call.h
│           ├── dbus-protocol.h
│           ├── dbus-server.h
│           ├── dbus-shared.h
│           ├── dbus-signature.h
│           ├── dbus-syntax.h
│           ├── dbus-threads.h
│           └── dbus-types.h
├── lib
│   ├── cmake
│   │   └── DBus1
│   │       ├── DBus1Config.cmake
│   │       └── DBus1ConfigVersion.cmake
│   ├── dbus-1.0
│   │   └── include
│   │       └── dbus
│   │           └── dbus-arch-deps.h
│   ├── libdbus-1.a
│   ├── libdbus-1.la
│   ├── libdbus-1.so -> libdbus-1.so.3.32.4
│   ├── libdbus-1.so.3 -> libdbus-1.so.3.32.4
│   ├── libdbus-1.so.3.32.4
│   └── pkgconfig
│       └── dbus-1.pc
├── libexec
│   └── dbus-daemon-launch-helper
├── share
│   ├── dbus-1
│   │   ├── services
│   │   ├── session.conf
│   │   ├── session.d
│   │   ├── system.conf
│   │   ├── system.d
│   │   └── system-services
│   ├── doc
│   │   └── dbus
│   │       ├── diagram.png
│   │       ├── diagram.svg
│   │       ├── examples
│   │       │   ├── example-session-disable-stats.conf
│   │       │   ├── example-system-enable-stats.conf
│   │       │   ├── example-system-hardening-without-traditional-activation.conf
│   │       │   └── GetAllMatchRules.py
│   │       └── system-activation.txt
│   └── xml
│       └── dbus-1
│           ├── busconfig.dtd
│           ├── catalog.xml
│           └── introspect.dtd
└── var
    ├── lib
    │   └── dbus
    └── run
        └── dbus

30 directories, 50 files
root@ubuntu:~/share/gateway/app/dbus/dbus_install# 

2.编译出来的文件要放到工具链
cp dbus_install/include/* /root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot/usr/include/ -rf
cp dbus_install/lib/* /root/share/nuvoton_cross/host/usr/arm-nuvoton-linux-gnueabi/sysroot/usr/lib/ -rf

3.编译出来的文件放到开发板

拷到开发板  主要拷贝跟拷贝到根文件系统的东西是一样的

但我用scp拷贝

scp bin/* root@192.168.2.99:/usr/bin/ 


scp lib/*so* root@192.168.2.99:/usr/lib/

ln -sf libdbus-1.so.3.32.4 libdbus-1.so
ln -sf libdbus-1.so.3.32.4 libdbus-1.so.3

scp -r etc/* root@192.168.2.99:/etc/

mkdir -p /var/run/dbus
 

4.libexpat.so也需要拷贝到开发板

root@buildroot:~$ /usr/bin/dbus-daemon
/usr/bin/dbus-daemon: error while loading shared libraries: libexpat.so.1: cannot open shared object file: No such file or directory
root@buildroot:~$ 

还需要拷贝expat库

拷贝到开发板
root@ubuntu:~/share/gateway/app/openlib/expat_install# scp bin/xmlwf root@192.168.2.99:/usr/bin/
root@ubuntu:~/share/gateway/app/openlib/expat_install# scp lib/*so* root@192.168.2.99:/usr/lib/

 

5.启动dbus守护进程

/usr/bin/dbus-daemon --system

问题(1)启动DBus守护进程时遇到了'Failed to start message bus: Could not get UID and GID for username “messagebus”'的问题,通过创建messagebus用户解决了此问题。

创建用户:
messagebus 

或者改dbus-1/system.conf的用户为root,我选择改成root。因为没必要创建那么多用户。

即将dbus目录下dbus-1/system.conf文件中的 <user>messagebus</user>改成root

问题(2)dbus找配置文件居然找我编译的时候config的prefix目录

root@buildroot:~$ /usr/bin/dbus-daemon --system
dbus[1790]: Failed to start message bus: Failed to open "/root/share/gateway/app/dbus/dbus_install/share/dbus-1/system.conf": No such file or directory
root@buildroot:~$ 

--system默认从这里找目录/usr/share/dbus-1/system.conf   --system是用这个目录

如何让dbus默认找/usr/share/dbus-1/system.conf文件呢?

GNU Make中,有许多约定俗成的东西,比如这个DESTDIR:用于加在要安装的文件路径前的一个前缀变量。
比如,我们本地编译了一个第三方库,但需要对其打包发布给其他人使用,一方面如果我们安装到默认目录,
比如/usr,这时,安装后的文件一但数量很大,则打包时很难找全;或者我们在configure时指定了--prefix,或cmake时指定了CMAKE_INSTALL_PREFIX,则pc文件内的编译依赖关系又会出错,变成了我们指定的那个路径,使用起来会很不方便。此时,DESTDIR就会派上用场。
DESTDIR只在make install时起作用,且和Makefile是由什么工具生成的没有关系,用法如下:
make install DESTDIR=<$CUSTOM_PREFIX>1
在configure或cmake时,指定了要安装的路径后,以这种方式make install安装的文件会通通安装到以$CUSTOM_PREFIX为前缀的目录中,这样,开发者直接对这目录中的文件打包,即可发布使用。

解决方法:

解决方法:重新编译dbus,要带DESTDIR

举例
./configure CC="arm-linux-gcc" --host=arm-linux --with-x=no --cache-file=arm-linux.cache
make
make DESTDIR=/home/make/dbus install

实际执行
make install DESTDIR=/root/share/gateway/app/dbus/dbus_install_240819

root@ubuntu:~/share/gateway/app/dbus# tree dbus_install_240819/
dbus_install_240819/
└── root
    └── share
        └── gateway
            └── app
                └── dbus
                    └── dbus_install
                        ├── bin
                        │   ├── dbus-cleanup-sockets
                        │   ├── dbus-daemon
                        │   ├── dbus-launch
                        │   ├── dbus-monitor
                        │   ├── dbus-run-session
                        │   ├── dbus-send
                        │   ├── dbus-test-tool
                        │   ├── dbus-update-activation-
                        
                        
明显有问题


还得改

执行
./configure --prefix=/usr --host=arm-nuvoton-linux-gnueabi CC=/root/share/nuvoton_cross/host/usr/bin/arm-nuvoton-linux-gnueabi-gcc --with-xml=libxml 

make 

make install DESTDIR=/root/share/gateway/app/dbus/dbus_install_240819

root@ubuntu:~/share/gateway/app/dbus/dbus_install_240819# scp -r usr/* root@192.168.2.99:/usr/
root@192.168.2.99's password: 
dbus-cleanup-sockets                                                                                                   100%   12KB  12.5KB/s   00:00    
dbus-test-tool                                                                                                         100%   23KB  22.9KB/s   00:00    
dbus-launch                                                                                                            100%   24KB  23.6KB/s   00:00    
dbus-send                                                                                                              100%   31KB  30.6KB/s   00:00    
dbus-run-session                                                                                                       100%   14KB  14.0KB/s   00:00    
dbus-update-activation-environment                                                                                     100%   13KB  13.4KB/s   00:00    
dbus-daemon                                                                                                            100%  313KB 313.0KB/s   00:00    
dbus-monitor                                                                                                           100%   27KB  27.1KB/s   00:00    
dbus-uuidgen                                                                                                           100% 8836     8.6KB/s   00:00    
session.conf                                                                                                           100%  838     0.8KB/s   00:00    
system.conf                                                                                                            100%  833     0.8KB/s   00:00    
dbus-memory.h                                                                                                          100% 1961     1.9KB/s   00:00    
dbus-macros.h                                                                                                          100% 7246     7.1KB/s   00:00    
dbus-connection.h                                                                                                      100%   26KB  26.4KB/s   00:00    
dbus-signature.h                                                                                                       100% 3047     3.0KB/s   00:00    
dbus-shared.h                                                                                                          100% 5392     5.3KB/s   00:00    
dbus-syntax.h                                                                                                          100% 2359     2.3KB/s   00:00    
dbus-errors.h                                                                                                          100% 2909     2.8KB/s   00:00    
dbus.h                                                                                                                 100% 3961     3.9KB/s   00:00    
dbus-address.h                                                                                                         100% 2809     2.7KB/s   00:00    
dbus-types.h                                                                                                           100% 4143     4.1KB/s   00:00    
dbus-message.h                                                                                                         100%   15KB  14.9KB/s   00:00    
dbus-threads.h                                                                                                         100% 8505     8.3KB/s   00:00    
dbus-protocol.h                                                                                                        100%   23KB  23.4KB/s   00:00    
dbus-bus.h                                                                                                             100% 3470     3.4KB/s   00:00    
dbus-misc.h                                                                                                            100% 1810     1.8KB/s   00:00    
dbus-pending-call.h                                                                                                    100% 3809     3.7KB/s   00:00    
dbus-server.h                                                                                                          100% 5412     5.3KB/s   00:00    
dbus-arch-deps.h                                                                                                       100% 2064     2.0KB/s   00:00    
dbus-1.pc                                                                                                              100%  658     0.6KB/s   00:00    
libdbus-1.so.3                                                                                                         100%  470KB 469.9KB/s   00:00    
libdbus-1.a                                                                                                            100%  550KB 550.1KB/s   00:00    
DBus1Config.cmake                                                                                                      100% 3193     3.1KB/s   00:00    
DBus1ConfigVersion.cmake                                                                                               100%  367     0.4KB/s   00:00    
libdbus-1.so.3.32.4                                                                                                    100%  470KB 469.9KB/s   00:00    
libdbus-1.la                                                                                                           100%  952     0.9KB/s   00:00    
libdbus-1.so                                                                                                           100%  470KB 469.9KB/s   00:00    
dbus-daemon-launch-helper                                                                                              100%   80KB  80.1KB/s   00:00    
system-activation.txt                                                                                                  100% 3175     3.1KB/s   00:00    
diagram.svg                                                                                                            100%   33KB  33.1KB/s   00:00    
example-session-disable-stats.conf                                                                                     100%  610     0.6KB/s   00:00    
example-system-hardening-without-traditional-activation.conf                                                           100% 1048     1.0KB/s   00:00    
example-system-enable-stats.conf                                                                                       100%  576     0.6KB/s   00:00    
GetAllMatchRules.py                                                                                                    100% 3924     3.8KB/s   00:00    
diagram.png                                                                                                            100%   77KB  76.9KB/s   00:00    
catalog.xml                                                                                                            100%  612     0.6KB/s   00:00    
introspect.dtd                                                                                                         100% 1226     1.2KB/s   00:00    
busconfig.dtd                                                                                                          100% 1907     1.9KB/s   00:00    
session.conf                                                                                                           100% 3573     3.5KB/s   00:00    
system.conf                                                                                                            100% 5830     5.7KB/s   00:00    
root@ubuntu:~/share/gateway/app/dbus/dbus_install_240819# 


root@buildroot:~$ /usr/bin/dbus-daemon --system
dbus[1790]: Failed to start message bus: Failed to open "/root/share/gateway/app/dbus/dbus_install/share/dbus-1/system.conf": No such file or directory
root@buildroot:~$ /usr/bin/dbus-daemon --system
dbus-daemon[2193]: Failed to start message bus: Could not get UID and GID for username "messagebus"


编辑/usr/share/dbus-1/system.conf文件的用户messagebus改成root


 2231 root     /usr/bin/dbus-daemon --system
 2232 root     ps
root@buildroot:~$ dbus-monitor --system
signal time=1104540730.701132 sender=org.freedesktop.DBus -> destination=:1.0 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.0"
signal time=1104540730.708866 sender=org.freedesktop.DBus -> destination=:1.0 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.0"
 

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值