everyone.
I'm working on ubuntu, developing this application using the glib resources, I wrote a makefile like this:
INCLUDES= -I ./headers
FLAGS= -g
PKGCONFIGCFLAGS= `pkg-config --cflags qmi-glib` `pkg-config --cflags gio-2.0` `pkg-config --cflags gobject-2.0` `pkg-config --cflags glib-2.0` `pkg-config --cflags gmodule-no-export-2.0` `pkg-config --cflags gmodule-2.0`
PKGCONFIGLIBS= `pkg-config --libs qmi-glib` `pkg-config --libs gio-2.0` `pkg-config --libs glib-2.0` `pkg-config --libs gobject-2.0` `pkg-config --libs gmodule-no-export-2.0` `pkg-config --libs gmodule-2.0`
CC=gcc
OBJECTS=./build/qmi_test.o
all: ${OBJECTS}
$(CC) ${FLAGS} ${INCLUDES} ./sources/main.c ${OBJECTS} -o ./bin/main
./build/qmi_test.o:./sources/qmi_test.c
$(CC) ${FLAGS} ${INCLUDES} ${PKGCONFIGCFLAGS} ./sources/qmi_test.c ${PKGCONFIGLIBS} -lm -o ./build/qmi_test.o
As you may notice, I inserted every glib related resource I found because I keep receiving this in return:
/usr/bin/ld: ./build/qmi_test.o: in function `g_autoptr_cleanup_generic_gfree':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28: undefined reference to `g_free'
/usr/bin/ld: ./build/qmi_test.o: in function `qmi_test1':
/home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:24: undefined reference to `g_file_new_for_path'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:25: undefined reference to `g_main_loop_new'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:26: undefined reference to `g_cancellable_new'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:29: undefined reference to `g_main_loop_run'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:31: undefined reference to `g_object_unref'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:32: undefined reference to `g_main_loop_unref'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:33: undefined reference to `g_object_unref'
/usr/bin/ld: ./build/qmi_test.o: in function `Device_Create_Start':
/home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:42: undefined reference to `g_file_get_path'
/usr/bin/ld: /home/myUser/Documents/quectel_eg25-g/./sources/qmi_test.c:45: undefined reference to `qmi_device_new'
collect2: error: ld returned 1 exit status
make: *** [Makefile:13: all] Error 1
I read in that the order of ellements when calling gcc does matter. But I'm trying to follow the order of elements as shown here:
glib compiling
Any help or recommendation is welcome.
You need to add the library flags (PKGCONFIGLIBS) to the link step and not the compile step:
all: ${OBJECTS}
$(CC) ${FLAGS} ${INCLUDES} -lm ./sources/main.c ${OBJECTS} ${PKGCONFIGLIBS} -lm -o ./bin/main
./build/qmi_test.o:./sources/qmi_test.c
$(CC) ${FLAGS} ${INCLUDES} ${PKGCONFIGCFLAGS} ./sources/qmi_test.c -o ./build/qmi_test.o
Related
Hi I am trying to use jpeglib in my code and i have trouble linking it with my Makefile
I downloaded it in tar.gz file then extracted it and did all the ./configure then the makes and all this stuff but now I have to link it in Makefile and I dunno how here is the Makefile
CFLAGS+= -Wall -Werror -fPIE -std=gnu99 -g
LDFLAGS= -pthread
HW=prgsem
BINARIES=prgsem
#LDFLAGS += -L/usr/local/lib -ljpeglib
#CXXFLAGS += -I/usr/local/include
CFLAGS+=$(shell sdl2-config --cflags)
LDFLAGS+=$(shell sdl2-config --libs) -lSDL2_image
all: ${BINARIES}
OBJS=${patsubst %.c,%.o,${wildcard *.c}}
prgsem: ${OBJS}
${CC} ${OBJS} ${CXXFLAGS} ${LDFLAGS} -o $#
${OBJS}: %.o: %.c
${CC} -c ${CFLAGS} $< -o $#
clean:
rm -f ${BINARIES} ${OBJS}
The commented stuff is what I tried and didnt work. Also I tried to change the #include itself. Tried #include "jpeglib.h" also #include <jpeglib.h> nothing worked.
EDIT: added make compile error message
cc xwin_sdl.o event_queue.o prg_io_nonblock.o gui.o main.o prgsem.o messages.o keyboard.o computation.o utils.o -pthread -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2 -lSDL2_image -o prgsem
/usr/bin/ld: gui.o: in function `save_img':
/home/peter/Cprog/bab36prga-sem/gui.c:67: undefined reference to `jpeg_std_error'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:69: undefined reference to `jpeg_CreateCompress'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:74: undefined reference to `jpeg_stdio_dest'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:81: undefined reference to `jpeg_set_defaults'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:83: undefined reference to `jpeg_start_compress'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:90: undefined reference to `jpeg_write_scanlines'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:93: undefined reference to `jpeg_finish_compress'
/usr/bin/ld: /home/peter/Cprog/bab36prga-sem/gui.c:97: undefined reference to `jpeg_destroy_compress'
collect2: error: ld returned 1 exit status
make: *** [Makefile:19: prgsem] Error 1
Thanks for any answers.
Your problem is not during the compilation phase of your program, so changing the #include etc. won't help in this case.
Your problem is during the linking phase, so that means you have not added the library to your link line. If, for example, the library is named libjpeg.a or libjpeg.so, then you need to add -ljpeg to your link line. The easiest way is to add it to the end of LDFLAGS:
LDFLAGS+=$(shell sdl2-config --libs) -lSDL2_image -ljpeg
I have spent several days now trying to cross compile a c program on my windows machine. the code runs fine on my linux machine but I had too many errors trying to cross compile it on that machine. Now I'm using Cygwin and Mingw32.
CC = x86_64-w64-mingw32-gcc
CFLAGS = -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi1
-mwindows `sdl-config --cflags --libs`
OBJECTS = main.o fft.o draw.o table.o serial.o
main : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o main
%.o : %.c
$(CC) $(CFLAGS) -c $<
clean:
#echo Cleaning up...
rm -fr *.o main
#echo Done.
This is what my makefile looks like after editing it to what I thought was needed to cross compile it. But I get many undefined reference errors. I realize this question is very similar to a few others I've looked over on SO, but I cannot seem to find my mistake.
$ make
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c main.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c fft.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c draw.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c table.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -
lftdi1 -mwindows `sdl-config --cflags --libs` -c serial.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lGL -lGLU -lm -lSDL_image -
lfftw3 -
lftdi1 -mwindows `sdl-config --cflags --libs` main.o fft.o draw.o table.o
serial.o -o main
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
/usr/src/debug/mingw64-x86_64-runtime-5.0.3-1/crt/crt0_c.c:18: undefined reference to `WinMain'
fft.o:fft.c:(.text+0xa): undefined reference to `fftw_malloc'
fft.o:fft.c:(.text+0x1b): undefined reference to `fftw_malloc'
fft.o:fft.c:(.text+0x2c): undefined reference to `fftw_malloc'
fft.o:fft.c:(.text+0x4d): undefined reference to `fftw_plan_dft_r2c_1d'
fft.o:fft.c:(.text+0x73d): undefined reference to `fftw_execute'
draw.o:draw.c:(.text+0xb): undefined reference to `__imp_glShadeModel'
draw.o:draw.c:(.text+0x1e): undefined reference to `__imp_glClearColor'
draw.o:draw.c:(.text+0x43): undefined reference to `gluOrtho2D'
draw.o:draw.c:(.text+0x4e): undefined reference to `__imp_glDisable'
draw.o:draw.c:(.text+0x5e): undefined reference to `__imp_glEnable'
draw.o:draw.c:(.text+0x82): undefined reference to `__imp_glViewport'
draw.o:draw.c:(.text+0x8e): undefined reference to `__imp_glMatrixMode'
draw.o:draw.c:(.text+0x97): undefined reference to `__imp_glLoadIdentity'
draw.o:draw.c:(.text+0xbe): undefined reference to `gluOrtho2D'
draw.o:draw.c:(.text+0xeb): undefined reference to `SDL_Init'
draw.o:draw.c:(.text+0xf4): undefined reference to `SDL_GetVideoInfo'
draw.o:draw.c:(.text+0x11c): undefined reference to `SDL_GL_SetAttribute'
draw.o:draw.c:(.text+0x13a): undefined reference to `SDL_SetVideoMode'
draw.o:draw.c:(.text+0x171): undefined reference to `SDL_GetError'
draw.o:draw.c:(.text+0x1a1): undefined reference to `SDL_GetError'
draw.o:draw.c:(.text+0x1d1): undefined reference to `SDL_GetError'
draw.o:draw.c:(.text+0x244): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x24b): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x252): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x29f): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x415): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x42c): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x447): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x4ef): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x55b): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x574): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x580): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x5e4): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x602): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x638): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x648): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x664): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x6b8): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x6e8): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x6fb): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x717): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x76b): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x7b5): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0x80d): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x814): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0x935): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0xa00): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0xa07): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0xa0e): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0xb0b): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0xc09): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0xc10): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0xc19): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0xc20): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0xea7): undefined reference to `__imp_glClear'
draw.o:draw.c:(.text+0xeb2): undefined reference to `__imp_glMatrixMode'
draw.o:draw.c:(.text+0xeb8): undefined reference to `__imp_glLoadIdentity'
draw.o:draw.c:(.text+0xec7): undefined reference to `__imp_glTranslatef'
draw.o:draw.c:(.text+0xf48): undefined reference to `__imp_glBegin'
draw.o:draw.c:(.text+0xf72): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0xf8f): undefined reference to `__imp_glVertex2f'
draw.o:draw.c:(.text+0xfba): undefined reference to `__imp_glEnd'
draw.o:draw.c:(.text+0x1089): undefined reference to `SDL_GL_SwapBuffers'
draw.o:draw.c:(.text+0x10c3): undefined reference to `__imp_glColor3ub'
draw.o:draw.c:(.text+0x10d8): undefined reference to `SDL_GetKeyState'
draw.o:draw.c:(.text+0x133d): undefined reference to `SDL_WM_ToggleFullScreen'
draw.o:draw.c:(.text+0x1364): undefined reference to `SDL_PollEvent'
draw.o:draw.c:(.text+0x1385): undefined reference to `SDL_PollEvent'
draw.o:draw.c:(.text+0x13ab): undefined reference to `SDL_SetVideoMode'
draw.o:draw.c:(.text+0x13e1): undefined reference to `SDL_GetError'
serial.o:serial.c:(.text+0x11): undefined reference to `ftdi_init'
serial.o:serial.c:(.text+0x1f): undefined reference to `ftdi_set_interface'
serial.o:serial.c:(.text+0x32): undefined reference to `ftdi_usb_open'
serial.o:serial.c:(.text+0x45): undefined reference to `ftdi_set_baudrate'
serial.o:serial.c:(.text+0x94): undefined reference to `ftdi_get_error_string'
serial.o:serial.c:(.text+0xc7): undefined reference to `ftdi_get_error_string'
serial.o:serial.c:(.text+0x139): undefined reference to `ftdi_write_data'
serial.o:serial.c:(.text+0x233): undefined reference to `ftdi_write_data'
collect2: error: ld returned 1 exit status
make: *** [makefile:6: main] Error 1
When you link to a SO in Linux , for example with -lGL, you are linking the shared object directly libGL.so.
But in Windows, when you link a DLL you are actually linking a static library libGL.a (libGL.lib in native Windows) that contains one thunk per imported function.
And as it happens, linker rules are different between shared and static libraries. Static libraries are linked using the order in the linker command line.
TL;DR; You have to put the -l* at the end of the linker command. Also, it is a good practice to separate CFLAGS and LDFLAGS:
CC = x86_64-w64-mingw32-gcc
CFLAGS = -Wall -O2 `sdl-config --cflags`
LDFLAGS = -lmingw32 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi1 -mwindows `sdl-config --libs`
OBJECTS = main.o fft.o draw.o table.o serial.o
main : $(OBJECTS)
$(CC) -o $# $(CFLAGS) $(OBJECTS) $(LDFLAGS)
%.o : %.c
$(CC) $(CFLAGS) -c $<
About the WinMain reference, that is because you wrote -mwindows: that is to build a Windows application, that is one that starts with WinMain() instead of main(). If you want to stick to your main() you can use -mconsole instead.
I switched the objects and cflags at the top, but forgotten to switch objects and cflags in
main : $(OBJECTS)
$(CC) $(OBJECTS) $(CFLAGS) -o main
Now I only get a undefined reference to WinMain
$ make
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lm -lGL -lGLU -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c main.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lm -lGL -lGLU -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c fft.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lm -lGL -lGLU -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c draw.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lm -lGL -lGLU -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c table.c
x86_64-w64-mingw32-gcc -Wall -O2 -lmingw32 -lm -lGL -lGLU -lSDL_image -
lfftw3 -lftdi1 -mwindows `sdl-config --cflags --libs` -c serial.c
x86_64-w64-mingw32-gcc main.o fft.o draw.o table.o serial.o -Wall -O2 -
lmingw32 -lm -lGL -lGLU -lSDL_image -lfftw3 -lftdi1 -mwindows `sdl-config --
cflags --libs` -o main
/usr/x86_64-w64-mingw32/sys-
root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function
`main':
/usr/src/debug/mingw64-x86_64-runtime-5.0.3-1/crt/crt0_c.c:18: undefined
reference to `WinMain'
collect2: error: ld returned 1 exit status
make: *** [makefile:6: main] Error 1
I'm trying to build a software that uses gstreamer-1.0 and its plugins. I get this error when I try to make using the following g++ command:
g++ vis.cpp -o vis -O3 -D__STDC_CONSTANT_MACROS -std=c++11 -lopencv_highgui -lopencv_imgproc -lopencv_core -lpng -lv4l1 -lv4l2 -ldc1394 -lswscale -lavdevice -lavformat -lavcodec -lswresample -lavutil -lpthread -lbz2 -lz -lc -lrt -llzma -lva -Idependencies/include -Ldependencies/lib `pkg-config --cflags --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0 gstreamer-pbutils-1.0 gtk+-2.0`
cap_gstreamer.cpp:(.text._ZN23CvVideoWriter_GStreamer4openEPKcid6CvSizeb+0x434): undefined reference to `gst_riff_create_video_caps'
collect2: error: ld returned 1 exit status
make: *** [vis] Error 1
Isn't gst_riff_create_video_caps already in the base plug-in? Or do I have to link another plugin for it?
I solved my problem. Obviously, I had to add -lgstriff-1.0 to the library flags as pointed out here:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gstreamer-riff.html
I have the file blah.c containing:
#include <gobject-introspection-1.0/girepository.h>
int main(int argc,char **argv) {
GIRepository *gir = g_irepository_get_default();
return 0;
}
This, of course, is simpler than the file I wish to compile, but has the same problem. I compile with
gcc `pkg-config --cflags --libs gobject-introspection-1.0` blah.c
and get the linking error:
/tmp/cck88oj4.o: In function `main':
blah.c:(.text+0x10): undefined reference to `g_irepository_get_default'
collect2: ld returned 1 exit status
The pkg-config command returns
-pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/gobject-introspection-1.0 -Wl,--export-dynamic -pthread -lgirepository-1.0 -lgobject-2.0 -lgmodule-2.0 -lffi -lgthread-2.0 -lrt -lglib-2.0
and the files libgirepository-1.0.a and libgirepository-1.0.so are both present in /usr/lib.
What is causing this linking error?
The reason for the linking error could be because the linker is linking with -Wl, as-needed option by default. When this option is used, the libraries are not linked until symbol in the library is encountered. In your current case as the source file is added in the end, none of the symbols in the libraries are encountered, thus linking is not done. You could try:
gcc blah.c `pkg-config --cflags --libs gobject-introspection-1.0`
or
gcc -Wl,-no-as-needed `pkg-config --cflags --libs gobject-introspection-1.0` blah.c
Hope this helps!
I'm trying to compile a C program, with these headers: http://pastebin.com/SppCXb0U , 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
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.