I am new to using DBUS and would like to compile a program that uses glib-2.0.
However I get an error. Here is my output from calling make:
g++ -I. -Wall -std=c++11 main.c `pkg-config --cflags --libs glib-2.0 dbus-1
dbus-glib-1` -o main.o
main.c: In function ‘int main(int, char**)’:
main.c:12:15: warning: variable ‘client’ set but not used [-Wunused-but-set-variable]
GDBusClient *client;
^
/tmp/ccNkl0Zc.o: In function `main':
main.c:(.text+0x20): undefined reference to `g_dbus_setup_bus'
main.c:(.text+0x44): undefined reference to `g_dbus_client_new'
collect2: error: ld returned 1 exit status
makefile:9: recipe for target 'main.o' failed
make: *** [main.o] Error 1
I tried following the instructions found on gnome.org https://developer.gnome.org/glib/stable/glib-compiling.html
This is my make file:
CC=g++
CFLAGS=-I. -Wall -std=c++11 \
-I/usr/include/dbus-1.0 \
-I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/ \
-I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \
-I/usr/include/glib-2.0
OBJ = main.o
default: program
main.o: main.c hello.h
$(CC) $(CFLAGS) main.c `pkg-config --cflags --libs glib-2.0` -o main.o
program: $(OBJ)
$(CC) $(OBJ) $(CFLAGS) -o program
clean:
-rm -f main.o
-rm -f program
This is my main:
#include <cstddef>
#include <cstdio>
#include <iostream>
#include <glib.h>
#include <dbus/dbus.h>
#include <gdbus/gdbus.h>
static DBusConnection *dbus_conn;
int main(int argc, char * argv[]){
GDBusClient *client;
dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
return 0;
}
Why am I getting undefined reference to these calls?