简体   繁体   English

X11 依赖,不使用 X11 编译 Dbus,只启动 Shell C++ Applications Raspbian Linux

[英]X11 Dependency, Compile Dbus without X11, starting only Shell C++ Applications Raspbian Linux

Hello Dear SO Community :)你好亲爱的SO社区:)

I am trying to get DBus working on my Raspberry Pi.我正在尝试让 DBus 在我的 Raspberry Pi 上工作。 The example code from libdbus-c++-1 is working fine when i am in the Pi Desktop environment -> (startx)当我在 Pi 桌面环境中时,来自 libdbus-c++-1 的示例代码运行良好 - > (startx)

My researches on the internet and the examples i found on stackoverflow didnt help me :[.我在互联网上的研究以及我在 stackoverflow 上找到的示例对我没有帮助:[。

However, when i am in the Shell-Mode i get the error message但是,当我处于 Shell 模式时,我收到错误消息

./client
terminate called after throwing an instance of 'DBus::Error'
  what():  /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
Aborted

i also tried我也试过

eval 'dbus-launch --auto-syntax' ./client

eval 'dbus-launch --auto-syntax' ./server

but it does not work, the server app is starting a message daemon but it is not reachable from the client.但它不起作用,服务器应用程序正在启动一个消息守护程序,但它无法从客户端访问。 Also the daemon stays active.守护进程也保持活动状态。

i got:我有:

terminate called after throwing an instance of 'DBus::Error'
  what():  The name org.freedesktop.DBus.Examples.Echo was not provided by any .service files
call1: Aborted

also it does not shown in the services list.它也没有显示在服务列表中。

after this i tried another command在此之后我尝试了另一个命令

DISPLAY=":0" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/dbus/system_bus_socket" ./server

and i got:我得到了:

terminate called after throwing an instance of 'DBus::Error'
  what():  Connection ":1.10" is not allowed to own the service "org.freedesktop.DBus.Examples.Echo" due to security policies in the configuration file
Aborted

:( after that is also not working i found a way to compile the dbus without the X11 Code with :( 之后也无法正常工作,我找到了一种在没有 X11 代码的情况下编译 dbus 的方法

./configure --with-x=no

unfortunately it has no effect.不幸的是它没有效果。 Still require X11 to start my applications... What do i wrong?仍然需要 X11 来启动我的应用程序...我做错了什么?

but commands like但是像这样的命令

eval 'dbus-launch --auto-syntax' dbus-monitor

How can i start my applications without starting X11 i dont need it and i dont want it.如何在不启动 X11 的情况下启动我的应用程序,我不需要它,我也不想要它。 Thank you for your help and time.感谢您的帮助和时间。

kindly regards oOm亲切的问候 oOm

# #

Update i feel a bit silly now but i found a way to run it without the x11更新我现在感觉有点傻,但我找到了一种无需 x11 即可运行它的方法

first you need to start a dbus session daemon首先你需要启动一个 dbus 会话守护进程

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357
DBUS_SESSION_BUS_PID=2465

this will prompt you your DBUS_SESSION_BUS_ADRESS这将提示您您的 DBUS_SESSION_BUS_ADRESS

DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357" ./server

after that you can launch your c++ application like this之后,您可以像这样启动您的 c++ 应用程序

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-send --session --dest=org.freedesktop.DBus   --type=method_call --print-reply                 /org/freedesktop/DBus org.freedesktop.DBus.ListNames

you can registered services with你可以注册服务

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-monitor

and monitoring the messages with并监控消息

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-monitor

but one question is left, how can i do it automatically?但是还有一个问题,我怎样才能自动做到这一点?

Great post.很棒的帖子。 You obviously had more diligence than I;你显然比我勤奋; I ended up running a display buffer instead.我最终改为运行显示缓冲区。

but one question is left, how can i do it automatically?但是还有一个问题,我怎样才能自动做到这一点?

Since自从

$dbus-launch 

outputs the bus info to standard out, did you try just running the program after?将总线信息输出到标准输出,您是否尝试过运行程序? For instance例如

$dbus-launch ./server

The dbus-launch man page says: dbus-launch 手册页说:

You may specify a program to be run;您可以指定要运行的程序; in this case, dbus-launch will launch a session bus instance, set the appropriate environment variables so the specified program can find the bus, and then execute the specified program, with the specified arguments.在这种情况下,dbus-launch 将启动一个会话总线实例,设置适当的环境变量以便指定的程序可以找到总线,然后使用指定的参数执行指定的程序。 See below for examples.请参阅下面的示例。

If you launch a program, dbus-launch will not print the information about the new bus to standard output.如果您启动一个程序,dbus-launch 不会将有关新总线的信息打印到标准输出。

but one question is left, how can i do it automatically?但是还有一个问题,我怎样才能自动做到这一点?

take a look at dbus-launch manual :看看dbus-launch手册

backticks or the $() construct can be used to read information from dbus-launch .反引号或 $() 构造可用于从dbus-launch读取信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM