I know this is rather outdated, but I recently had the same issue, found this question without any real answer and was finally able to solve it. So hopefully this will help others having the same issue.
The problem was related to different function name mangling between C and C++, so if you include the GLib files from C++ code, you will get the undefined reference
errors.
The solution was to change my includes from
#include <gio/gio.h>
#include <glib.h>
to
extern "C" {
#include <gio/gio.h>
#include <glib.h>
}
After that, compilation (and linking!) worked just fine.