如何编译一个基本的D-Bus /巧舌如簧的例子吗? [英] How to compile a basic D-Bus/glib example?

查看:272
本文介绍了如何编译一个基本的D-Bus /巧舌如簧的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何使用的D-Bus与C绑定。我以前从未使用过的D-Bus。我下面这个教程,我以为是官方一(Freedesktop.org)。我读过它,直到这个给人的第一样本程序
,但遗憾的是我没有看到这个页面了解如何编译或库中包括的任何迹象。我错过了什么?

I'm trying to learn how to use D-Bus with C bindings. I've never used D-Bus before. I'm following this tutorial, which I assume is the official one (Freedesktop.org). I've read it until this paragraph that gives a first sample program , but unfortunately I don't see any indication on this page about how to compile it or which libraries to include. Did I miss something ?

我的操作系统是Ubuntu的10.04 32位。我安装了 libdbus-能说会道-1-dev的包。我尝试添加的#include< D​​BUS / dbus.h> 在源文件的开头,并编译

My OS is Ubuntu 10.04 32bit. I installed the libdbus-glib-1-dev package. I tried to add #include <dbus/dbus.h> at the beginning of the source file, and to compile with

$ gcc -ldbus-1 -I/usr/include/dbus-1.0/ -I/usr/lib/i386-linux-gnu/dbus-1.0/include -o my_dbus.bin my_dbus.c

但我只是不停地失败:

but I just keep failing:

my_dbus.c: In function ‘main’:
my_dbus.c:7:3: error: unknown type name ‘DBusGConnection’
my_dbus.c:8:3: error: unknown type name ‘GError’
...

我错过了在本教程的一个点?它不是,请你帮我编这一块code的?

Did I miss a point in the tutorial ? It not, could you please help me compile this piece of code ?

先谢谢了。

推荐答案

像这样的教程通常假设你拥有它是书面语言的一些知识,在这种情况下,C,以及你的操作系统将运行它打开。

Tutorials like this one generally assume that you have some knowledge of the language it is written for, in this case C, as well as the operating system you will run it on.

纵观本教程中,我看到它仅包含一个功能。因此,你需要为了添加适当的的#include 指令这个工作:

Looking at the tutorial, I see that it only contains a main function. As such, you will need to add the proper #include directives in order for this to work:

#include <stdlib.h>          // for exit()   
#include <dbus/dbus.h>       // for dbus_*   
#include <dbus/dbus-glib.h>  // for dbus_g_*

此外,您还需要编译的库(在这种情况下, DBUS 的dbus-巧舌如簧),或使用pre-编译那些从你的操作系统,以便将其链接到可执行文件。

Also, you will need to compile the libraries (in this case dbus and dbus-glib), or use the pre-compiled ones from your operating system, in order to link them to the executable.

您还会从操作系统需要提供源的头文件,还是发展的包。

You will also need the header files provided with the source, or the "development" packages from your operating system.

每例如,我的Ubuntu的工作站上,我可以安装源和头两个文件,​​像这样:

Per example, on my Ubuntu workstation, I can install both the source and the header files like so:

sudo apt-get -y install dbus libdbus-1-dev libdbus-glib-1-2 libdbus-glib-1-dev

一旦被编译(或正确安装)后即可进行编译程序。您需要指定正确的包含路径和库链接到编译器/连接。每例如,GCC和我的当前设置将是:

Once they are compiled (or properly installed), you proceed to compile the program. You will need to specify the proper include paths and libraries to link to the compiler/linker. Per example, with GCC and my current setup it would be:

gcc test.c -I/usr/include/dbus-1.0 \
           -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include \
           -I/usr/include/glib-2.0 \
           -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
           -ldbus-1 \
           -ldbus-glib-1
           -Wall -Wextra

这应该建立在当前目录中执行的a.out

This should create an execute a.out in the current directory.

当然,我有几年的经验,C和Linux的,所以我得到很容易弄清楚所有的东西。如果你正在寻找开始与C,你应该先从一些比较容易,但。

Granted, I have a few years of experience with C and Linux so I get figure out all that stuff easily. If you're looking to start with C, you probably should start with something easier though.

这篇关于如何编译一个基本的D-Bus /巧舌如簧的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆