Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 417 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiling C program with dbus header files

#1
I'm trying to compile a C program, with these headers:

[To see links please register here]

, on Ubuntu. At first I didn't have any luck at all, but after reading about pkg-config I crafted this line:

gcc `pkg-config --cflags --libs dbus-1` `pkg-config --cflags --libs glib-2.0` signals-tutorial.c

However, it still doesn't work and gives me this error:


/tmp/cc3BkbdA.o: In function `filter_example':
signals-tutorial.c:(.text+0x1a3): undefined reference to `dbus_connection_setup_with_g_main'
/tmp/cc3BkbdA.o: In function `proxy_example':
signals-tutorial.c:(.text+0x29a): undefined reference to `g_type_init'
signals-tutorial.c:(.text+0x2b3): undefined reference to `dbus_g_bus_get'
signals-tutorial.c:(.text+0x323): undefined reference to `dbus_g_proxy_new_for_name'
signals-tutorial.c:(.text+0x369): undefined reference to `dbus_g_proxy_add_signal'
signals-tutorial.c:(.text+0x38a): undefined reference to `dbus_g_proxy_connect_signal'
collect2: ld returned 1 exit status


I'm not sure what to do from here.

==================================

A nice explanation - thank you. However, I can't get it working. Running your command above (with an added \) yield the following result

gcc `pkg-config --cflags dbus-1` \
> `pkg-config --cflags glib-2.0` \
> signals-tutorial.c \
> `pkg-config --libs dbus-1` \
> `pkg-config --libs glib-2.0`
/tmp/ccjN0QMh.o: In function `filter_example':
signals-tutorial.c:(.text+0x1a3): undefined reference to `dbus_connection_setup_with_g_main'
/tmp/ccjN0QMh.o: In function `proxy_example':
signals-tutorial.c:(.text+0x29a): undefined reference to `g_type_init'
signals-tutorial.c:(.text+0x2b3): undefined reference to `dbus_g_bus_get'
signals-tutorial.c:(.text+0x323): undefined reference to `dbus_g_proxy_new_for_name'
signals-tutorial.c:(.text+0x369): undefined reference to `dbus_g_proxy_add_signal'
signals-tutorial.c:(.text+0x38a): undefined reference to `dbus_g_proxy_connect_signal'
collect2: ld returned 1 exit status
Reply

#2
Your problem isn't with the header files, your problem is with the libraries; complaints about "undefined references" generally come from the linker. You need to put the library configuration options **after** the source file:

gcc `pkg-config --cflags dbus-glib-1` \
`pkg-config --cflags dbus-1` \
`pkg-config --cflags glib-2.0` \
signals-tutorial.c \
`pkg-config --libs dbus-glib-1` \
`pkg-config --libs dbus-1` \
`pkg-config --libs glib-2.0`

The `--libs` option will produce a series of `-l` flags for the compiler, the compiler will pass those to the linker. The linker will resolve symbols from left to right starting with the object file (or, close enough in this case, the C source file) so all the library `-l` switches need to follow your source file.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through